I have a 2X2 Grid that is filled with 2 Listview controls and some buttons and textboxes on my main app window. Below is part of my XAML code:
<Grid Name="Gd">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ListView MinHeight="600" Grid.Column="0" Grid.Row="1" Margin="10">
<ListView.View>
<GridView>
<GridViewColumn Width="330" Header="Module ID" />
</GridView>
</ListView.View>
</ListView>
<ListView MinHeight="600" Grid.Column="0" Grid.Row="2" Margin="10">
<ListView.View>
<GridView>
<GridViewColumn Width="330" Header="Module Name" />
</GridView>
</ListView.View>
</ListView>
</Grid>
The difficulty I have got here is that I don’t know how to set the width that equals the width of Grid column. Should I do it in the code behind? Also, another problem is that the above code can’t handle the situation where Grid is resized.
Ideally, I want the ListView control to fill the Grid column and expand/shrink accordingly whenever the size of Grid changes. I guess it has something to do with the ColumnDefinition Settings, which I am not very sure of.
Can anyone help? Thanks a lot.
If you are putting your ListView in the first column, your column definitions should looks like the following:
Aslo, as guys already said, set
HorizontalAlignment="Stretch"for bothListViewcontrols