I have a WPF MainWindow.xaml which contians a grid which has got two list boxes as follows:
<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. These do nothing for you, as the outer Grid
only has a single (default) row and ditto column. In fact, you don't need the outer Grid
at all; you could just have your Border
as the Window
content.
Also consider changing this:
<RowDefinition Height="35"/>
to this:
<RowDefinition Height="Auto"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.