2

I want to disable row selection if a property is set to a value

I tried:

<DataGrid ...>
   <DataGrid.CellStyle>
     <Style TargetType="DataGridCell">
       <Style.Triggers>
          <DataTrigger Binding="{Binding Path=IsBusy}" Value="True">
            <Setter Property="here I don't know" Value="False" />
          </DataTrigger>
       </Style.Triggers>
     </Style>
   </DataGrid.CellStyle>
</DataGrid>

I don't want to disable entire DataGrid because horizontal scroll is not scrollable anymore, so I avoid this.

Snake Eyes
  • 16,287
  • 34
  • 113
  • 221
  • Possible duplicate of [wpf: DataGrid disable selected row styles - or row selecting](https://stackoverflow.com/questions/3046988/wpf-datagrid-disable-selected-row-styles-or-row-selecting) – Rekshino May 09 '19 at 11:12

1 Answers1

1

If you want to unselect the entire row, try with a RowStyle instead and set the property IsSelected to false when your your data trigger is true:

<DataGrid>
   <DataGrid.RowStyle>
     <Style TargetType="DataGridRow">
       <Style.Triggers>
          <Setter Property="Foreground" Value="Black" />
          <DataTrigger Binding="{Binding Path=IsBusy}" Value="True">
            <Setter Property="IsSelected" Value="False" />
          </DataTrigger>
          <Trigger Property="IsSelected" Value="False">
            <Setter Property="Foreground" Value="Black" />
          </Trigger>
       </Style.Triggers>
     </Style>
   </DataGrid.RowStyle>
   <DataGrid.CellStyle>
       <Style TargetType="DataGridCell">
           <Setter Property="Foreground" Value="Black" />
           <Style.Triggers>
               <Trigger Property="IsSelected" Value="True">
                   <Setter Property="Background" Value="{x:Null}" />
                   <Setter Property="BorderBrush" Value="{x:Null}" />
               </Trigger>
           </Style.Triggers>
       </Style>
   </DataGrid.CellStyle>
</DataGrid>
Isma
  • 14,604
  • 5
  • 37
  • 51