2012-04-05 108 views
7

我有一个WPF DataGrid被用于数据输入,但一些DataGridTextColumn只是信息,我已经设置了它们的IsReadOnly="True",以便它们的单元不进入编辑模式。但是,他们仍然可以获得我想避免的焦点。如何使WPF Datagrid列不可聚焦?

有没有办法做到这一点?

回答

11

使用单元格样式并设置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}"/> 

    ....