2016-07-12 4 views
0

定義済みのジェスチャーによって、メソッドXceedCopyCommandExecuteを実行しようとしましたが、このメソッドは一度も呼び出されていません。このジェスチャーを使用するときは、列ヘッダーで行全体をコピーするだけです。 withnout headercolumnをコピーしないようにしてください。どのようにそれを解決するための任意のアイデア?何かアドバイスctrl + cまたはshift + cでコピー反応がありません

public static RoutedCommand XceedCopyCommand = new RoutedCommand();  
    public CommandBinding XceedCopyCommandBinding { get { return xceedCopyCommandBinding; } } 
    private CommandBinding xceedCopyCommandBinding; 

    public BaseView() 
    { 
     XceedCopyCommand.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift)); 
     xceedCopyCommandBinding = new CommandBinding(XceedCopyCommand, XceedCopyCommandExecuted); 
    } 

    private void XceedCopyCommandExecuted(object sender, ExecutedRoutedEventArgs e) 
    { 
     if (sender == null || !(sender is Xceed.Wpf.DataGrid.DataGridControl)) return; 

     var dataGrid = sender as Xceed.Wpf.DataGrid.DataGridControl; 

     dataGrid.ClipboardExporters[DataFormats.UnicodeText].IncludeColumnHeaders = false; 

     var currentRow = dataGrid.GetContainerFromItem(dataGrid.CurrentItem) as Xceed.Wpf.DataGrid.Row; 
     if (currentRow == null) return; 

     var currentCell = currentRow.Cells[dataGrid.CurrentColumn]; 
     if (currentCell != null && currentCell.HasContent) 
     { 
      Clipboard.SetText(currentCell.Content.ToString()); 
     } 
    } 

答えて

0

あなたは新しいコマンドを作成し、結合していますが、データグリッドに割り当てるされていない、結果としてデータグリッドは、それがでているコマンドを使用していきますされているため、事前に

感謝そのCommandBindingsコレクション。

デフォルトの 'コピー'コマンドを削除してから、自分で追加する必要があります。例えば

// Remove current Copy command 
int index = 0; 
foreach (CommandBinding item in this.myGrid.CommandBindings) 
{ 
    if (((RoutedCommand)item.Command).Name == "Copy") 
    { 
     this.myDataGrid.CommandBindings.RemoveAt(index); 
     break; 
    } 
    index++; 
} 

// Add new Copy command 
this.myDataGrid.CommandBindings.Add(xceedCopyCommandBinding); 
関連する問題