1

I know ContextMenus aren't part of the visual tree, but I've been trying to bind the Visibility property of a ContextMenu to 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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That's a really great helper class. Thanks.
Thankyou, Thankyou, Thankyou, Thankyou, Thankyou, Thankyou. I found this question/answer while looking for a solution to something else. ElementSpy is EXACTLY what I needed. +1 for sure.
0

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}}" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.