【问题标题】:How to make WPF Datagrid Column non-focusable?如何使 WPF Datagrid 列不可聚焦?
【发布时间】:2012-04-05 15:31:18
【问题描述】:

我有一个 WPF DataGrid 用于数据输入,但一些 DataGridTextColumn 仅供参考,我已设置它们的 IsReadOnly="True",因此它们的单元格不会进入编辑模式。但是,他们仍然可以获得我想要避免的焦点。

有没有办法做到这一点?

【问题讨论】:

    标签: wpf focus wpfdatagrid datagridtextcolumn


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 2010-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多