6

I have a WPF DataGrid being used for data entry but some DataGridTextColumn are information only and I have set their IsReadOnly="True" so their cells do not go into edit mode. However, they can still receive focus which I want to avoid.

Is there a way to do this?

Shaminder Singh
  • 1,283
  • 2
  • 18
  • 31
Gary Barrett
  • 1,764
  • 5
  • 21
  • 33

1 Answers1

12

Use a cell style and set Focusable=False.

<Page.Resources>
    <Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}">
        <Setter Property="Focusable" Value="False"/>
    </Style>
</Page.Resources>

<DataGrid ItemsSource="{Binding Items}" ...>
    <DataGrid.Columns>
        <DataGridTextColumn 
            CellStyle="{StaticResource CellStyle}" 
            IsReadOnly="True" 
            Header="Name" Binding="{Binding Name}"/>

    ....
Phil
  • 42,255
  • 9
  • 100
  • 100