且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从上下文菜单项绑定到父控件

更新时间:2022-06-16 02:23:45

修改(示出了控制是如何暴露后):
那么文本菜单是有点棘手,因为它实际上是不一样的视觉树的一部分。试着这样做:

EDIT (after showing how the control is exposed): Well ContextMenu is somewhat tricky, because it's actually not part of the same visual tree. Try doing this:

<MenuItem Command="{Binding Path=PlacementTarget.SaveToClipboardCommand,
    RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>

原来的答复

这是命令公开为公共
  控制财产?如果
  命令在实际曝光
  视图模型悬挂控制的中
  DataContext的,要做到以下几点:

Is this command exposed as a public property of the Control? If the command is actually exposed in a ViewModel hanging of the control's DataContext, to do the following:

Command={Binding ElementName=Control, Path=DataContext.SaveToClipboardCommand}

您可以显示该命令是如何
  目前暴露的?

Can you show how this command is currently exposed?