I want to disable DataRow selection in WPF DataGrid.
First I have tried IsHitTestVisible
property, it disables whole row. If I want to put an HyperLink
it will be disabled.
I have tried to get rid of it by overriding DataGridRow
ControlTemplate
's :
(Whole template code is huge but i just put the important section)
<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>
Actually selecting a row in DataGrid will change Forground
color. I have tried Triggers
but it won't work. In the code above, I have tried to keep foreground Black
but it throws in a run-time error.
How can i disable Row selection in a DataGrid ?