Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change margin programmatically in WPF / C#

Tags:

c#

wpf

xaml

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#?

like image 328
yozawiratama Avatar asked Apr 10 '11 12:04

yozawiratama


People also ask

How do I set margins in WPF?

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.

How does margin work WPF?

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.

What is Padding in WPF?

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.

How does margin work in XAML?

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.


2 Answers

test.Margin = new Thickness(0, -5, 0, 0); 

Alignment, Margins and Padding Overview (MSDN)
FrameworkElement.Margin (MSDN)

like image 182
Eben Geer Avatar answered Sep 20 '22 10:09

Eben Geer


test.Margin = new Thickness(0, 0, 0, 0); 
like image 36
Andrey Avatar answered Sep 22 '22 10:09

Andrey