【问题标题】:WPF DataGrid 'Select All Button' followed by Control-CWPF DataGrid“选择所有按钮”,后跟 Control-C
【发布时间】:2016-08-12 07:09:26
【问题描述】:

在加载 WPF DataGrid 之后,我点击了“全选按钮”(左上角),然后是 Control-C。

但是这个序列不会将数据网格项复制到我的剪贴板。

我怎样才能做到这一点?

【问题讨论】:

    标签: wpf


    【解决方案1】:

    单击该按钮时,似乎数据网格不会自行聚焦,因此您必须自己修复它:

    dataGrid.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, OnDataGridSelectAll));
    

    然后:

    private void OnDataGridSelectAll(object sender, ExecutedRoutedEventArgs e) {
        var grid = (DataGrid)sender;
        grid.Focus();
        grid.SelectAll();
    }
    

    如果需要,您还可以在 xaml 中添加命令绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-19
      • 2013-01-08
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 2010-12-02
      相关资源
      最近更新 更多