How to make WPF Datagrid Column non-focusable?
Asked Answered
A

1

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?

Ailsa answered 5/4, 2012 at 15:31 Comment(0)
M
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}"/>

    ....
Melson answered 9/4, 2012 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.