I have a ListView in WPF set to GridView, and it has a context menu. How do I only enable the context menu when there is something selected in the ListView?
I want to do all this in XAML to follow the MVVM pattern, so any help would be good.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should use Triggers. Define the ContextMenu as a resource first.
Here is a short sample:
Saying all that, I cannot imagine a real scenario when this is what you want to do. First, right clicking on the ListView (to popup the context menu) will select an item. Second – I think this is a bad UI design. It would be better to show the same menu, but disable the items (all the items in your case). This way, it gives the user an indication that a popup menu exists, but its functionality isn’t enabled right now.