[英]Dock WPF ListBox to window
I have a WPF MainWindow.xaml which contians a grid which has got two list boxes as follows: 我有一个WPF MainWindow.xaml,它包含一个具有两个列表框的网格,如下所示:
<Window blah blah >
<Grid>
<Border Grid.Row="1" Grid.Column="0" BorderBrush="DarkGray" CornerRadius="2" BorderThickness="1" >
<Grid Height="Auto" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0">ListBox 1</Label>
<ListBox x:Name="lvTypes" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Visibility="Visible" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="150" Background="#FFFFFFFF">
</ListBox>
<GridSplitter Grid.Column="0" Grid.RowSpan="2" Width="5"></GridSplitter>
<Label Grid.Row="0" Grid.Column="1">ListBox 2</Label>
<ListBox x:Name="lvObjects" Grid.Column="1" Grid.Row="1" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="150">
</ListBox>
</Grid>
</Border>
</Grid>
</Window>
It looks as follows: 它看起来如下:
How can I get the right hand side of the grid to dock to the right hand side of the screen and for the two list boxes to be equal in the window? 我如何才能使网格的右侧停靠在屏幕的右侧,并使窗口中的两个列表框相等?
Set column widths to * instead of Auto. 将列宽设置为*而不是自动。
Your border sets Grid.Row
and Grid.Column
properties. 边框设置
Grid.Row
和Grid.Column
属性。 These do nothing for you, as the outer Grid
only has a single (default) row and ditto column. 这些对您无济于事,因为外部
Grid
仅具有一个(默认)行和同上列。 In fact, you don't need the outer Grid
at all; 实际上,您根本不需要外部
Grid
。 you could just have your Border
as the Window
content. 您可以将“
Border
作为“ Window
内容。
Also consider changing this: 还可以考虑更改此:
<RowDefinition Height="35"/>
to this: 对此:
<RowDefinition Height="Auto"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.