For this xaml:
<WebBrowser Name="test" Margin="0,0,0,0" />
How can I change the web browser control margin on top to be -5 programmatically in C#?
The Margin property of UIElement, which is parent class of all WPF controls is used to set the margin of a control. Margin property takes four numbers - Left, Top, Right and Bottom, that is margin to the left top and right bottom.
The margin is the space between an element and the parent element or other adjacent element on the same parent element. The margin adds extra space around the outside edges of an element. The Margin property of FrameworkElement represents the margin of an element. It is a type of Thickness structure.
Padding represents the distance between the side of the control (which can be the margin) and its content. The content depends on the type of the control. Margin is outside the UI element, while Padding is inside it.
XAML ValuesMargin="20,50" will be interpreted to mean a Thickness with Left and Right set to 20, and Top and Bottom set to 50. The default unit for a Thickness measure is device-independent unit (1/96th inch). You can also specify other units by appending the unit type strings cm , in , or pt to any measure.
test.Margin = new Thickness(0, -5, 0, 0);
Alignment, Margins and Padding Overview (MSDN)
FrameworkElement.Margin (MSDN)
test.Margin = new Thickness(0, 0, 0, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With