#326 – Specifying a Symmetrical Margin Using Two Arguments

You can set the Margin property on a control so that it has some extra room around its edges, within its container.

You can specify a value for the Margin property in XAML using either one, two or four integer values.  Using one value indicates the margin for each of the four sides of the control.  Using four values indicates the left/top/right/bottom margin values individually.

When you use two values in specifying the Margin, you are specifying the combined left-right and top-bottom margins.  I.e. Margin=”left+right, top+bottom.

        <Label Content="Gene Autry the singing cowboy" Background="Pink" />
        <Button Content="I Like Gene" Margin="10,20"/>
        <Label Content="Roy Rogers" Background="Aqua" />

The value of 10 indicates that the left and right margins should be identical and add up to 10 WPF units.  Using the two-argument version results in symmetrical margins.

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: