私は TargetType=DataGridCell のスタイルを持っています。これには ContextMenu が含まれています。CommandParameter を介してそのコマンドに DataGridCell 情報を渡す必要があります。
<Style TargetType="{x:Type DataGridCell}" x:Key="DataGridCellStyle">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Copy" Command="{Binding CopyToClipBoardCommand, Mode=OneWay}" CommandParameter={}>
<MenuItem.DataContext>
<cust:CopytoContext/>
</MenuItem.DataContext>
</MenuItem>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
xmlns:cust="clr-namespace:MyProject.Util"
クラスのソースコード
public class CopytoContext
{
#region Commands
public ICommand CopyToClipBoardCommand
{
get
{
return new DelegatingCommand((object param) =>
{
new Action(() =>
{
/// Logic to Copy the Content to Clipboard
}).Invoke();
});
}
}
#endregion
}
現在の DataGridCell 情報をそのコマンドに渡す方法。助けてください...