2012-04-05 50 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}"/> 

    ....