Snake Eyes
Snake Eyes

Reputation: 16764

Disable row selection datagrid WPF when a property is set to a value

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.

Upvotes: 2

Views: 130

Answers (1)

Isma
Isma

Reputation: 15209

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>

Upvotes: 1

Related Questions