WPF Datagridを使用していて、コピーと貼り付けのメカニズムを強化/変更しようとしています。
ユーザーがいくつかのセルを選択してからCTRL+Cを押すと、基になるコントロールはCopyingRowClipboardContentイベントをキャッチできます。
this.mainDataGrid.CopyingRowClipboardContent
+= this.DatagridOnCopyingRowClipboardContent;
この方法では、一部のセルがヘッダーと行の両方に追加されるため、「幅の広い」グリッドになります。
private void DatagridOnCopyingRowClipboardContent(
object sender,
DataGridRowClipboardEventArgs dataGridRowClipboardEventArgs)
{
// this is fired every time a row is copied
var allContent = dataGridRowClipboardEventArgs.ClipboardRowContent;
allContent.Insert(0, new DataGridClipboardCellContent(
null,
this.mainDataGrid.Columns[0],
"new cell"));
}
この時点で、ヘッダーの前に行を追加し、最後の行の後に2行追加しようとしているため、スタックしています(下の画像を参照)。
何か案は?提案?
ここでは、MVVMでそれを行う方法には興味がないことに注意してください。