Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DevExpress TableView单元格的焦点不在CopyingToClipboard事件上_C#_Wpf_Devexpress_Devexpress Wpf - Fatal编程技术网

C# DevExpress TableView单元格的焦点不在CopyingToClipboard事件上

C# DevExpress TableView单元格的焦点不在CopyingToClipboard事件上,c#,wpf,devexpress,devexpress-wpf,C#,Wpf,Devexpress,Devexpress Wpf,我正在尝试修复此自定义的DevExpress表视图。正如您所猜测的,下面的方法处理CopyingToClipboard。当我投射FocusedElement时,它是一个BaseEdit,但不是我准确选择的那个。它的显示文本是不同的 我已经更改了单元格的背景色,以确保它具有焦点,并且是选中的单元格。这不是问题所在。你能分享一下你的智慧吗 private void CustomizedTableView_CopyingToClipboard(object sender, CopyingToClipb

我正在尝试修复此自定义的DevExpress表视图。正如您所猜测的,下面的方法处理CopyingToClipboard。当我投射FocusedElement时,它是一个BaseEdit,但不是我准确选择的那个。它的显示文本是不同的

我已经更改了单元格的背景色,以确保它具有焦点,并且是选中的单元格。这不是问题所在。你能分享一下你的智慧吗

private void CustomizedTableView_CopyingToClipboard(object sender, CopyingToClipboardEventArgs e)
    {
        TableView view = sender as TableView;

        if (view == null || view.Grid == null)
        {
            return;
        }

        BaseEdit edit = System.Windows.Input.Keyboard.FocusedElement as BaseEdit;
        edit.Background = Brushes.Red;
        VantageUtilities.SafeCopyToClipboard(DataFormats.Text, edit.DisplayText);
        e.Handled = true;            
    }
您可以使用属性获取聚焦编辑器,也可以使用属性获取聚焦值。
下面是一个例子:

private void CustomizedTableView_CopyingToClipboard(object sender, CopyingToClipboardEventArgs e)
{
    TableView view = sender as TableView;

    if (view == null || view.Grid == null)
        return;

    string text = null;

    if (view.ActiveEditor != null)
        text = view.ActiveEditor.DisplayText;
    else
    {
        object value = view.Grid.CurrentCellValue;

        if (value != null)
            text = value.ToString();
    }

    if (text == null)
        return;

    VantageUtilities.SafeCopyToClipboard(DataFormats.Text, text);
    e.Handled = true;
}
PS:DataControlBase中有一些
CopySomethingToClipboard
方法:方法、方法、方法、方法和方法。你可以看看