行或列定义可以根据其内容的尺寸自动调整大小吗

发布于 2024-07-14 05:41:41 字数 1519 浏览 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>

So for example... in the following user control I have a grid with two rows. I want the bottom row to be the height of it's contents and the top row to be the height of the rest of the grid. I can set a absolute height as in the example, but that isn't particularly flexible. Say someone changes a font sizing the text could get clipped. Is there any built in way to achieve this?

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咿呀咿呀哟 2024-07-21 05:41:41

在 WPF 中,这很简单:

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

我怀疑 Silverlight 中也有同样的效果?

In WPF this is as simple as:

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

I suspect the same works in Silverlight?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文