开发者

WPF: Binding ContextMenu to visual parent

I know ContextMenus aren't part of the visual tree, but I've been trying to bind the Visibility property of a ContextMenu t开发者_如何学运维o a property on its parent UserControl. So far I've tried ancestor binding and experimented with a converted, but the only way that seems remotely feasible at the minute is to use a MultiValueConverter and reflection to pass the type names and property names on the UserControl. Even then I'm not sure it would work.

Am I going about this the wrong way?


a context menu is only visible when you right click, so you should not need to set its visibility. maybe you should be using a popup.

however if you want to do some funky bindings you can use element spy from the excellent josh smith to use element name bindings to bind between things that arent usually possible.


I'm not sure why you would need to bind the visibility of a ContextMenu... but anyway, here's a solution that should work :

<ContextMenu Visibility="{Binding PlacementTarget.Visibility, RelativeSource={RelativeSource Self}}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜