行高设置为“自动”的WPF网格布局面板 [英] WPF Grid layout panel with row height set to "Auto"

查看:210
本文介绍了行高设置为“自动”的WPF网格布局面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在顶部和底部有一排有标签或按钮的格子。在中间我打算使用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 =300d:DesignWidth =300>
<网格>
< 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>


解决方案
pre $ < RowDefinition Height =*/>


I'd like to have a Grid with a row on the top and bottom with either labels or buttons in them. In the middle I plan on using a ListBox. I want the ListBox to expand to use all the available space. It would be nice to not hard code the height of the other two rows. My XAML is below. How can I make the middle section expand automatically? Thanks.

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

解决方案

Try setting the middle row to this...

<RowDefinition Height="*" /> 

这篇关于行高设置为“自动”的WPF网格布局面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆