Friday 11 June 2010

Sizing elements in Silverlight

I keep having to remind myself about sizing in Silverlight but it’s easy really:

Sizing Type Description Usage
Absolute Choose the exact size in pixels. Changing the container size has no effect. Width=”100”
Automatic Element is given the exact amount of space it needs and no more. Width=”Auto”
Proportional Space is divided between elements in a group (e.g. rows in a Grid). A number can be given to proportionally assign space. Width=”*”
Width=”2*”

For example:

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="0.25*" />
        <RowDefinition Height="1.5*" />
        <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
</Grid>
Friday 11 June 2010