Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a top margin only in XAML?

Tags:

c#

wpf

xaml

margins

I can set margins individually in code but how do I do it in XAML, e.g. how do I do this:

PSEUDO-CODE:

<StackPanel Margin.Top="{Binding TopMargin}"> 
like image 375
Edward Tanguay Avatar asked Aug 22 '09 16:08

Edward Tanguay


People also ask

How do I set margins 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 I set margins in WPF?

The margin property in WPF allows you set spacing between elements in a window. You can assign the margins for the Top, Right, Bottom and Left. Every control that derives from FrameworkElement has this property.

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.


1 Answers

Isn't this what you're looking for?

<StackPanel Margin="0,10,0,0" /> 

The first value is Left margin, then Top, then Right, and last but not least Bottom.

I'm not sure if you want to bind it to something, but if not, that'll work.

like image 92
Carlo Avatar answered Sep 28 '22 11:09

Carlo