我正在尝试在列表视图中启用列标题的大小调整,我的样式中有一些设置不正确,我看不到拖动和调整大小的选项。当我删除lib使用时,Everythink工作正常。样式资源:
<Style x:Key="ListViewItem" TargetType="ListViewItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#76b900"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#76b900"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ListViewStyle" TargetType="{x:Type ListView}" >
<Setter Property="ItemContainerStyle" Value="{StaticResource ListViewItem}"/>
</Style>
<Style x:Key="GridViewColumnHeaderStyle1" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border BorderThickness="0,0,1,1" BorderBrush="Black" Background="Transparent">
<TextBlock x:Name="ContentHeader" Text="{TemplateBinding Content}"
Padding="5,5,5,5" Width="{TemplateBinding Width}" TextAlignment="Center" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Foreground" Value="#76b900" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Padding" Value="40,40" />
</Style>
XAML中的"我的列表"视图:
<ListView d:ItemsSource="{d:SampleData}" ItemsSource="{Binding PGroups}" SelectedItem="{Binding PGroupSelected}"
Foreground="White" Background="#292929" FontSize="16" BorderThickness="0"
Visibility="{Binding PGroupsVis}" Style="{DynamicResource ListViewStyle}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="False"
IsSynchronizedWithCurrentItem="True" >
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle1}">
<GridViewColumn Header="Group" DisplayMemberBinding="{Binding Name}" Width="220" ></GridViewColumn>
<GridViewColumn Header="Test Level" DisplayMemberBinding="{Binding Level.Name}" Width="140"></GridViewColumn>
<GridViewColumn Header="OverrideColumn" DisplayMemberBinding="{Binding OverrideColumn}" Width="140"></GridViewColumn>
<GridViewColumn Header="Active" DisplayMemberBinding="{Binding IsActive}" Width="140"></GridViewColumn>
<GridViewColumn Header="Remove">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button ToolTip="Remove"
Command="{Binding Path=DataContext.RemovePGroupCommand,
RelativeSource={RelativeSource AncestorType=ListView,
Mode=FindAncestor}}" CommandParameter="{Binding}"
VerticalAlignment="Center"
HorizontalAlignment="Center" Style="{StaticResource SimpleButton}">
<Image Source="../Images/delete3.png" Width="25"
Height="25" Visibility="{Binding ComboUsersVis}" ></Image>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
我试着用
<GridViewColumnHeader Content="Value" IsHitTestVisible="False"/>
但似乎不起作用。
我错过了什么?
1条答案
按热度按时间z3yyvxxp1#
您缺少用于调整页眉大小的缩略图。必须将其命名为PART_HeaderGripper:
当您重新模板化列标题时。
见
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/listview-styles-and-templates?redirectedfrom=MSDN&view=netframeworkdesktop-4.8
在你创建模板之前,最好仔细看看默认的模板是什么。模板通常比你想象的要复杂得多。命名控件通常是为了在该控件的代码中引用它们。错过它们或者错误地命名它们,你很可能会遇到问题。