ContextMenu on WindowsFormsHost control

2020-03-04 03:01发布

问题:

So, I have a WindowsFormsHost control in my WPF app (hosting a Dundas Chart) and I want to put a ContextMenu on it.

I can successfully attach a ContextMenu to any normal WPF control, but it's not working for the WindowsFormsHost. I suspect this is becuase it's "special" in some way and the appropriate mouse messages aren't reaching the required destination.

How do I do this?

回答1:

Answering my own question - I have made this work by capturing the MouseDown event on my Windows control I'm hosting (the Dundas Chart control) and then firing a new event.

The event handler for the new event then does:

graph.ContextMenu.IsOpen = true;

Works nicely.