我想在WPF DataGrid中禁用数据行选择。
首先我试过
IsHitTestVisible
属性,它将禁用整行。如果我想放一个
HyperLink
我试图通过推翻
DataGridRow
ControlTemplate
(整个模板代码很大,但我只放了重要的部分)
<VisualState x:Name="Normal_Selected">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="DGR_Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlMediumColor}" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="DGR_Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlDarkColor}" />
</ColorAnimationUsingKeyFrames>
<!--<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0" Value="Black" />
</ColorAnimationUsingKeyFrames>-->
</Storyboard>
</VisualState>
实际上,在DataGrid中选择一行将改变
Forground
颜色。我试过了
Triggers
但这行不通。在上面的代码中,我试图保持前景
Black
如何在数据网格中禁用行选择?