I got this xaml of a ListView
:
<ListView Grid.Row="4" Grid.Column="1"
ItemsSource="{Binding Path=ListViewAgentItems}"
HorizontalAlignment="Left"
HorizontalContentAlignment="Left">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn HeaderContainerStyle="{StaticResource ListViewStyle}" Header="Agent ID" DisplayMemberBinding="{Binding AgentId}"/>
<GridViewColumn HeaderContainerStyle="{StaticResource ListViewStyle}" Header="Distance" DisplayMemberBinding="{Binding Distance}"/>
</GridView>
</ListView.View>
</ListView>
This is the style:
<Window.Resources>
<Style x:Key="ListViewStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</Window.Resources>
I want both GridViewColumn
to take all the space evenly, meaning that the ListView
is in a grid column, so I want the GridView
to take the entire column space, and also that both columns of the GridView will take 50% of the width. As of now, the ListView is automatically sized to fit the data it holds which I don't want.