行高度设置为 "Auto"的WPF网格布局面板

标签 wpf layout grid

我想要一个网格,顶部和底部都有一行,其中有标签或按钮。在中间,我计划使用ListBox。我希望ListBox扩展为使用所有可用空间。最好不要对其他两行的高度进行硬编码。我的XAML在下面。如何使中间部分自动展开?谢谢。

<UserControl x:Class="WpfApplication1.UserControl1"
         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" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <Label Grid.Row="0"
           Grid.ColumnSpan="3"
           Content="Top Row" />

    <ListBox Grid.Row="1"
             Grid.ColumnSpan="3" />

    <Label Grid.Row="2"
           Grid.ColumnSpan="3"
           Content="Bottom Row" />
</Grid>

最佳答案

尝试将中间行设置为此...

<RowDefinition Height="*" /> 

关于行高度设置为 "Auto"的WPF网格布局面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3294368/

相关文章:

c# - 在XAML中将CollectionViewSource与CompositeCollection结合使用

c# - MVVM 可编辑组合框绑定(bind)

c# - DataGridColumnHeader 中的第一个下划线被删除

切换主题时 Delphi VCL 应用程序布局发生变化

database - 数据库网格中的符号是什么意思?

带有编辑器列的ExtJs TreeGrid。存在吗?

css - 在容器内平均定位 div

WPF 水平数据网格

java - 将单独类中的多个组件添加到另一个类中的 JFrame

node.js - 表示没有找到/使用布局