Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WPF form with many controls. Some of the controls have context menus (some built-in, some I added). I also added a context menu on the base Grid of the view to catch anything that doesn't have a context menu. All this works fine.

Now with the Grid context menu, sometimes I don't want it to display at all (like when I am in edit mode). The problem is whatever I do to the base Grid's context menu also happens to all of the other context menus in the view. I only want it to apply to the base Grid's context menu.

How can I separate the one context menu from all the rest? Unfortunately the ContextMenuOpening event doesn't tell me which context menu it it trying to open. The context menu doesn't have an "Opening" event. If I use "Opened" it flashes.

Any other ideas?

What I have tried:

Included in the problem above.

More things:
*The Loaded event - It is happy to make it hidden, not so much to bring it back to life.
*Visibility property - When I cancel the edit mode, the context menu pops up. It needs to wait for a right-click.
Posted
Updated 7-Jul-16 4:41am
v2

1 solution

Solved it myself:

I was using the wrong properties in the Loaded event.

C#
private void appHistory_Loaded(object sender, RoutedEventArgs e)
{
    ContextMenu cm = sender as ContextMenu;
    if (cm != null)
    {
        cm.IsOpen = Model.ShowDisplayHistory;
        e.Handled = true;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900