Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does XAML Margin not follow CSS norm?

Tags:

In CSS the margin order is: top right bottom left

In XAML the margin order is: left top right bottom

Is there a reason why the WPF team didn't align this to the CSS norm?

like image 429
Edward Tanguay Avatar asked Feb 06 '09 14:02

Edward Tanguay


People also ask

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.

How do you give a margin in XAML?

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. This example sets Margin of a Button control in XAML at design-time. Click Me!

What is padding in XAML?

The Padding property represents the distance between an element and its child elements, and is used to separate the control from its own content. Padding values can be specified on layout classes.

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. Next Recommended Reading WPF: Textblock Vs Label.


2 Answers

I imagine this is because margins in WinForms were declared as left, top, right, bottom. They likely thought it would be more likely to have WinForms developers move on to WPF rather than those from the web.

For reference you can check the constructor for the Padding structure on MSDN (the type used for the Margin property).

like image 80
Richard McGuire Avatar answered Sep 21 '22 22:09

Richard McGuire


They're not aligning to CSS norms - they're aligning with the way that Microsoft has done UI APIs in the past. I can't speak for WinForms, but in MFC coordinates are specified in the order of LTRB.

like image 23
17 of 26 Avatar answered Sep 19 '22 22:09

17 of 26