Beruflich Dokumente
Kultur Dokumente
Introduction
All user interface elements have a standard set of layout properties, mostly inherited from the Framework Element base class. These properties are shown in Table.
Property
Width Height MinWidth MaxWidth MinHeight MaxHeight HorizontalAlignment VerticalAlignment Margin Padding Visibility FlowDirection Panel.ZIndex
Usage
Specifies a fixed width Specifies a fixed height The minimum permissible width The maximum permissible width The minimum permissible height The maximum permissible height Horizontal position if element is smaller than available space Vertical position if element is smaller than available space Space around outside of element Space between element border and content Allows the element to be made invisible to the layout system where necessary Text direction Controls which elements are on top or underneath
element.
You should try to avoid using these in general it is preferable to let
the screen any wider, but as long as what you request is possible, it will be done.
an element.
If you need to constrain your user interface s layout, it is usually better to
honor that request unless you have some very exoticdisplay hardware.
In these cases, your element will be truncated to fit the space available.
element, meaning that any narrower elements are given excess space.
The default setting for both of these properties is Stretch when excess
its natural height or width, and will then be positioned to one side or in the center.
Margin
This property determines the amount of space that should be left around
the element during layout. You can specify Margin as a single number, a pair of numbers, or a list of four numbers.
When one number is used, this indicates that the same amount of space
the second indicates the space above and below. When four numbers are specified, they indicate the amount of space on the left, top, right, and bottom sides, respectively.
You can use the Margin property to control an element s position.
Example :- Controlling an element s position with Margin <Border BorderBrush="Black BorderThickness="1"> <Grid> <Rectangle Margin="20, 10, 0, 0" Fill="Green" Width="80" Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" /> </Grid> </Border>
Result:
Fig. Margin
Padding
Whereas Margin indicates how much space should be left around the
outside of an element, Padding specifies how much should be left between a control s outside and its internal content.
Example shows three buttons, one with just a margin, one with both a
margin and padding, and one with just padding. It also fills the area behind the buttons with color so that the effects of the margin can be seen.
Example :- Margin versus Padding <Grid ShowGridLines="True" Background="Cyan"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Button Grid.Column="0" Margin="20" Padding="0">Click me!</Button> <Button Grid.Column="1" Margin="10" Padding="10">Click me!</Button> <Button Grid.Column="2" Margin="0" Padding="20">Click me!</Button> </Grid>
Result:
Visibility
The Visibility property determines whether an element is visible. It has an
impact on layout, because if you set it to Collapsed, the preferred size of the element will become zero.
This is different from Hidden this indicates that although the element is
not visible, the layout system should treat it in the same way as it would if it were Visible.
FlowDirection
The FlowDirection property controls how text flows; the default is based
cultures use the alternative right-to-left style. Setting the FlowDirection property to RightToLeft affects the flow direction of all text, and of any WrapPanel elements contained within that element.
Example :- FlowDirection <StackPanel> <WrapPanel Orientation="Horizontal"> <Button>One</Button> <Button>Two</Button> <Button>Three</Button> </WrapPanel> <WrapPanel Orientation="Horizontal" FlowDirection="RightToLeft"> <Button>One</Button> <Button>Two</Button> <Button>Three</Button> </WrapPanel> </StackPanel> Result:
Panel.ZIndex
Panel defines an attached property, ZIndex, that determines which element
Panel.ZIndex. The default value is 0, so elements with a positive Panel.ZIndex will appear on top of those that do not specify one.
Example does not use Panel.ZIndex, so the element overlapping order is
Example2:- With Panel.ZIndex <Grid> <Button Width="75" Height="23" Margin="0,0" Panel.ZIndex="3" HorizontalAlignment="Left" VerticalAlignment="Top"> One </Button> <Button Width="75" Height="23" Margin="15,15" Panel.ZIndex="2" HorizontalAlignment="Left" VerticalAlignment="Top"> Two </Button> <Button Width="75" Height="23" Margin="30,30" Panel.ZIndex="1" HorizontalAlignment="Left" VerticalAlignment="Top"> Three </Button> </Grid>
Thank You.