1

I have been trying very hard to disable hover, mouse over and row selections on datagrid rows. I had used the following code for Wpf application in the past and it worked perfectly. However, I am in the middle of the process of migrating my code to the new Winui3 and I just can't make it work again.

but the problem is how to hide row selections. See this picture:

1

Here is the code that works for Wpf;

<controls:DataGrid.Style>
   <Style TargetType="controls:DataGridCell">
           <Setter Property="BorderBrush" Value="Transparent" />
           <Setter Property="FocusVisualStyle" Value="{x:Null}" />
  </Style>
</controls:DataGrid.Style>

Now, FocusVisualStyle doesn't exists. I was able to disable cell borders on selection by overriding some brush resources like these:

  <SolidColorBrush x:Key="DataGridCellFocusVisualPrimaryBrush" Color="Transparent" />
  <SolidColorBrush x:Key="DataGridCellFocusVisualSecondaryBrush" Color="Transparent" />
Andrew KeepCoding
  • 7,040
  • 2
  • 14
  • 21

1 Answers1

2

This should work:

<controls:DataGrid>
    <controls:DataGrid.Resources>
        <Color x:Key="DataGridRowSelectedBackgroundColor">Transparent</Color>
        <Color x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundColor">Transparent</Color>
        <Color x:Key="DataGridRowSelectedUnfocusedBackgroundColor">Transparent</Color>
        <!--
        This one is better not being just "Transparent".
        This way you won't lose visual effects for hovered selected rows.
        -->
        <StaticResource
            x:Key="DataGridRowSelectedHoveredBackgroundColor"
            ResourceKey="SystemListLowColor" />
    </controls:DataGrid.Resources>
</controls:DataGrid>

You can find the colors in the GitHub repo.

Andrew KeepCoding
  • 7,040
  • 2
  • 14
  • 21