ContextMenu Close event problem
Hi all,
We use ContextMenu in a Canvas in our project, when ContextMenu closed we want do something. How to determie the ContextMenu is closed by click out of the ContextMenu or clicked one item in the ContextMenu?
The ContextMenu Closing event happened before the item click event.
Thanks.
We use ContextMenu in a Canvas in our project, when ContextMenu closed we want do something. How to determie the ContextMenu is closed by click out of the ContextMenu or clicked one item in the ContextMenu?
The ContextMenu Closing event happened before the item click event.
Thanks.
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: ContextMenu Close event problem
Hi,
I verified the order of events in WPF and we are not raising them in the correct order.
If the user clicks a MenuItem the order should be:
1. MenuItem.Click
2. ContextMenu.Closed
We will fix it for the next release, sorry for the inconvenience.
Meanwhile, I don't know if it is possible in your situation, but maybe you can call VisualTreeHelper::HitTest() to decide if user clicked inside or outside the ContextMenu.
I verified the order of events in WPF and we are not raising them in the correct order.
If the user clicks a MenuItem the order should be:
1. MenuItem.Click
2. ContextMenu.Closed
We will fix it for the next release, sorry for the inconvenience.
Meanwhile, I don't know if it is possible in your situation, but maybe you can call VisualTreeHelper::HitTest() to decide if user clicked inside or outside the ContextMenu.
Re: ContextMenu Close event problem
Hi,
Hittest is not work, but we found another way to fix it.
Thanks.
Hittest is not work, but we found another way to fix it.
Thanks.
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: ContextMenu Close event problem
Could you explain why HitTest failed?
And what was your final solution? It can help others in the same situation.
Thanks a lot for your feedback.
And what was your final solution? It can help others in the same situation.
Thanks a lot for your feedback.
Re: ContextMenu Close event problem
Hi,
Hittest always return false when closed the menu.
The solution we used is just like Hittest. We record the rect of contextmenu when it loaded, then test the mouse position if it in the rect when contextmenu closed.
Hittest always return false when closed the menu.
The solution we used is just like Hittest. We record the rect of contextmenu when it loaded, then test the mouse position if it in the rect when contextmenu closed.
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: ContextMenu Close event problem
Ok, that makes sense, as MenuItems are being closed and removed from the tree until ContextMenu parent is reached and its Closed event is raised, so HitTest cannot find the original MenuItem then.Hittest always return false when closed the menu.
Thanks

Who is online
Users browsing this forum: No registered users and 0 guests