How do you do the equivalent of css's margin-top in WPF?
I have an image which I want to add a margin on the top, but all I can seem to get to work is margin, which effects each side of the image.
How do you do the equivalent of css's margin-top in WPF?
I have an image which I want to add a margin on the top, but all I can seem to get to work is margin, which effects each side of the image.
You can specify the margin for each side (in that order : left, top, right, bottom)
<Image Source="image.png" Margin="0,10,0,0"/>
You could use the left, top, right, bottom numbers to specify the margin for any control in WPF
For example:
<Button Margin="10 5 10 10" />
Here Left -> 10, Top -> 5, Right - 10 and Bottom -> 10
For more check this blog post WPF Margin demystified
Another useful blog post about Margins, Padding, Borders and Content, nice one
the Margin property is what you are looking for. There are 3 different ways to set the margin. The first one (see below) sets all of the margins to the same value--it expands out to "0,0,0,0".
the second one sets the left and right sides to 1 and the top and bottom sides to 0--it expands out to "1,0,1,0". and the third sets each side to an individual value (in this case, 5).
Margin values, in order:first value is left side
second value is top
third value is right side
fourth value is bottom
Margin="5"; <!-- same as "5,5,5,5" -->
Margin="5,2" <!-- same as "5,2,5,2" -->
Margin="5,6,7,8" <!-- set left,top,right,bottom independantly -->