共用方式為


GridUnitType Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Describes the kind of value that a GridLength object is holding.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Enumeration GridUnitType
public enum GridUnitType
<object property="enumMemberName"/>

Members

Member name Description
Supported by Silverlight for Windows Phone Auto The size is determined by the size properties of the content object.
Supported by Silverlight for Windows Phone Pixel The value is expressed in pixels.
Supported by Silverlight for Windows Phone Star The value is expressed as a weighted proportion of available space.

Remarks

Star sizing is used to distribute available space by weighted proportions.

In XAML, star sizings are expressed as * or 2*. In the first case, the row or column would receive a third of the available space. In the second case, the row or column would receive two-thirds of the available space, and so on.

Examples

The following example shows how to position some TextBlock objects and a Rectangle inside a Grid.

<Grid Background="#DCDCDC" 
ShowGridLines="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TextBlock Margin="2" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3"
           TextWrapping="Wrap">
    This TextBlock is positioned in the first column and the 
    first row (column 0, row 0) and spans across all three columns (ColumnSpan 3).
    </TextBlock>
    <TextBlock Grid.Column="0" Grid.Row="1" Margin="5" FontWeight="Bold">Rectangle:</TextBlock>
    <Rectangle Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Left" Fill="Red"
           Width="200" Height="50"/>
    <Button Grid.Column="0" Grid.Row="2" Content="Stretched Button" />
    <Border Background="White" BorderThickness="5" Grid.Row="2" Grid.Column="1" Grid.RowSpan="2" >
    <TextBlock TextWrapping="Wrap">
        This TextBlock spans across two rows.
    </TextBlock>
    </Border>
    <TextBlock Margin="5" Grid.Row="3" Grid.Column="0">1st Column, 4th Row</TextBlock>
    <TextBlock Margin="5" Grid.Row="3" Grid.Column="2">3rd Column, 4th Row</TextBlock>
</Grid>

The preceding example produces output that is similar to the following illustration. Note that the ShowGridLines property of the Grid is set to true so that you can see the lines of the Grid. ShowGridLines is useful for visualizing where the Grid cells are, but because grid lines cannot be styled or customized, they are typically removed when the layout design is finished.

grid sample

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Other Resources