Reputation: 1733
I have a grid view with 4 columns.
<ListView Grid.Row="0" Name="CallHistory" ItemsSource="{Binding CallDetails}" ItemContainerStyle="{DynamicResource ListViewItemStyle}" SelectionChanged="CallHistory_OnSelectionChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#FF474747" Foreground="White">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{DynamicResource ListColumnHeaderStyle}">
<GridViewColumn Width="150" Header="Year" DisplayMemberBinding="{Binding Year}" />
<GridViewColumn Width="85" Header="Time(sec)" DisplayMemberBinding="{Binding Duration.TotalSeconds, StringFormat={}{0:F2}}" />
<GridViewColumn Width="200" Header="Caller" DisplayMemberBinding="{Binding CallerName}"/>
<GridViewColumn Width="Auto" Header="Receipient" DisplayMemberBinding="{Binding ReceipientName}" />
</GridView>
</ListView.View>
</ListView>
Added a style to it in App.xaml
<Style TargetType="{x:Type GridViewColumnHeader}" x:Key="ListColumnHeaderStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border BorderThickness="0,0,0,1" BorderBrush="WhiteSmoke" Background="Transparent">
<TextBlock x:Name="ContentHeader" Text="{TemplateBinding Content}" Padding="5,5,5,0" Width="{TemplateBinding Width}" TextAlignment="Left" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="12" />
</Style>
With the above code, the user won't be able to resize the columns anymore. If I comment the "Template" and "OverridesDefaultStyle" setters in the style, I will get the non-styled GridView which I can resize. I want to keep the style along with column resize feature. Please let me know what I need to do for it.
Upvotes: 2
Views: 513
Reputation: 9944
You forgot to add the PART_HeaderGripper
when you overrode the GridViewColumnHeader
's ControlTemplate
:
<Style TargetType="{x:Type GridViewColumnHeader}" x:Key="ListColumnHeaderStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Grid>
<Border BorderThickness="0,0,0,1" BorderBrush="WhiteSmoke" Background="Transparent">
<TextBlock x:Name="ContentHeader" Text="{TemplateBinding Content}" Padding="5,5,5,0" Width="{TemplateBinding Width}" TextAlignment="Left" />
</Border>
<Thumb x:Name="PART_HeaderGripper"
HorizontalAlignment="Right"
Margin="0"
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="12" />
</Style>
Full ListView
's Style and Template for reference
Upvotes: 2