swinefeaster
swinefeaster

Reputation: 2555

Proper way to set MenuItem visibility in Context Menu?

I am trying to do things the .net way and declare my menu items for my context menu like a good citizen in xaml :).

I have a listbox that contains a bunch of list items based of ItemsSource.

QUESTION: How can I dynamically set the visibility of a particular menu item based off a function to be defined in the Page class?

I could just data bind this to a property in my DataContext class, but there are a few things that are more ui-specific that it really should not know about, so I'd like to keep it clean.

Can I somehow bind the visibility to a function in the page class and pass it the data context and have it return the appropriate visibility value required? Or is there another way?

Thanks! swine

Upvotes: 0

Views: 382

Answers (1)

Bryan Watts
Bryan Watts

Reputation: 1425

Bindings are useful because the UI updates whenever the bound value changes. Since a function doesn't update, even if you could bind to a function, the UI would never change. The UI would also never know when to call the bound function.

Why don't you just bind to a bool DataProperty and then use the function to update the bool. If you explain more of what you are trying to do, then I can give you a more detailed solution.

Upvotes: 1

Related Questions