我有一个 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 信息传递给该命令。请帮助我...