将网格设置为填满整个屏幕

3

我觉得问这个问题很蠢,但是我该如何设置网格以使用我的wpf页面的整个空间?我似乎无法将其高度设置为“*”,我希望它能够填充整个“DesignHeight/Width”当我更改它们。谢谢!

<Page x:Class="Aud10.MenuHome"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" Title="MenuHome" d:DesignHeight="860" d:DesignWidth="1196">
    <Grid Height="860" Width="1196">
        <Grid.RowDefinitions>
            <RowDefinition Height="0.5*" />
            <RowDefinition Height="0.5*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.333*" />
            <ColumnDefinition Width="0.333*" />
            <ColumnDefinition Width="0.333*" />
        </Grid.ColumnDefinitions>
    </Grid>
</Page>

我认为w.b的解决方案应该可以满足您的需求!但是有一个建议:如果您想让两行具有相同的高度,您不需要显式地声明它(“表示行高的GridLength。默认值为1.0。”,https://msdn.microsoft.com/de-de/library/system.windows.controls.rowdefinition.height(v=vs.110).aspx)。只需写两个 <RowDefinition /> 即可获得两行共享50%空间的效果(ColumDefinition同理)。 - SSchuette
哦,你说得对!谢谢你的建议! - Loukoum Mira
2个回答

8

只需完全删除WidthHeight设置,Grid就会自动填充所有可用空间。


0
<Grid >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <TextBlock Text="Label" Width="150" />
    <TextBox Text="Value" Grid.Column="0" />
</Grid>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接