I am trying to achieve following things
1. Set Minimum width for gridview column to some value.
2. When entries are added to this column, column width should adjust accordingly.
I have written following code for it
<Grid Background="white" Height="140" Width="auto">
<ListView Style="{StaticResource stl_lvi_TEXT}" Grid.Row="0" Grid.Column='0' Name="lv_includedInstruments" SelectionMode="Single" Background="White" Height="140" Width="auto" HorizontalAlignment ="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Coll_History}" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="lv_includedInstruments_SelectionChanged" TabIndex="18" GotFocus="lv_includedInstruments_GotFocus">
<ListView.View>
<GridView>
<GridViewColumn Width="212" >
<GridViewColumn.Header>
<GridViewColumnHeader Style="{StaticResource stl_ColumnHeaderStyle}" Content="Groups" HorizontalContentAlignment="Left" Background="white" FontSize="12" BorderBrush="#FF97BADA" BorderThickness="1" Tag="ProtocolVisitTypeForm.ProtocolName"/>
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Width="auto" Tag="{Binding}" Text="{Binding Path=ProtocolVisitTypeForm.ProtocolName}" >
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
stl_ColumnHeaderStyle is as follows
<Style x:Key="stl_ColumnHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock MinWidth="200" Width="auto" TextWrapping="Wrap" Text="{Binding}"></TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
this works fine when i add first entry of string of lenght x. But if subsequent entries are of greater than length x, then the column width does not expand.
Thank You.
You are already setting gridVIewColumn width explictly. It will never grow more than 212. Bind GridViewColumn.Width against GridViewColumn.Header.ActualWidth. It should be dynamic then.