行或列定义可以自动调整其内容的维度

时间:2009-02-11 12:00:06

标签: silverlight silverlight-2.0

所以例如......在以下用户控件中我有一个有两行的网格。我希望底行是其内容的高度,顶行是网格其余部分的高度。我可以像示例中那样设置绝对高度,但这不是特别灵活。假设有人更改了字体大小,文本可能会被剪裁。有没有内置的方法来实现这个目标?

<UserControl x:Class="Tournament.View.TeamCreator"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="20" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="1" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="1*" />
            </Grid.RowDefinitions>

            <TextBlock Grid.Column="0" Grid.Row="0" Text="TEAM NAME" />
            <TextBox Grid.Column="1" Grid.Row="0" />
            <TextBlock Grid.Column="2" Grid.Row="0" Text="MANAGER NAME" />
            <TextBox Grid.Column="3" Grid.Row="0" />
            <Button Grid.Column="4" Grid.Row="0" />
        </Grid>
    </Grid>
</UserControl>

1 个答案:

答案 0 :(得分:2)

在WPF中,这很简单:

<Grid.RowDefinitions>
    <RowDefinition Height="1*" />
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>

我怀疑Silverlight中的相同功能?