我可以使用没有IsMouseOver触发器的ControlTemplate来做到这一点。但是,根据下面的定义,调整列的大小和列之间的实际空间的能力会消失。那么如何禁用IsMouseOver触发器但保留所有其他功能呢?
<Style TargetType="{x:Type GridViewColumnHeader}" >
<Setter Property="FontWeight" Value="{StaticResource Theme.DataGrid.ColumnHeader.FontWeight}"></Setter>
<Setter Property="BorderBrush" Value="Transparent"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
<Setter Property="Background" Value="{StaticResource Theme.DataGrid.ColumnHeader.Background}"></Setter>
<Setter Property="Foreground" Value="{StaticResource Theme.DataGrid.ColumnHeader.Foreground}"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Left"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border x:Name="Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
编辑:在Suppress mouse hover effect on GridViewColumn中,接受的答案似乎解决了这个问题。
答案 0 :(得分:0)
即使答案中存在类似问题,我也会发布一个解决我问题的版本。它可能有一些问题,但它可能会让人知道如何解决他们的问题。
<Style TargetType="{x:Type GridViewColumnHeader}" >
<Setter Property="FontWeight" Value="{StaticResource Theme.DataGrid.ColumnHeader.FontWeight}"></Setter>
<Setter Property="BorderBrush" Value="Transparent"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
<Setter Property="Background" Value="{StaticResource Theme.DataGrid.ColumnHeader.Background}"></Setter>
<Setter Property="Foreground" Value="{StaticResource Theme.DataGrid.ColumnHeader.Foreground}"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Left"></Setter>
<Setter Property="Padding" Value="{StaticResource Theme.DataGrid.Cell.Padding}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<Thumb Grid.Column="1" x:Name="PART_HeaderGripper" HorizontalAlignment="Right" Margin="-8,0,0,0"
Style="{DynamicResource GridView.ColumnHeader.Gripper.Style}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>