decai
Topic Author
Posts: 31
Joined: 06 Jul 2016, 18:19

ContextMenu Close event problem

18 Oct 2016, 09:33

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.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: ContextMenu Close event problem

19 Oct 2016, 03:09

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.
 
decai
Topic Author
Posts: 31
Joined: 06 Jul 2016, 18:19

Re: ContextMenu Close event problem

19 Oct 2016, 07:18

Hi,

Hittest is not work, but we found another way to fix it.

Thanks.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: ContextMenu Close event problem

19 Oct 2016, 12:11

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.
 
decai
Topic Author
Posts: 31
Joined: 06 Jul 2016, 18:19

Re: ContextMenu Close event problem

20 Oct 2016, 14:10

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.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: ContextMenu Close event problem

21 Oct 2016, 11:08

Hittest always return false when closed the menu.
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.

Thanks ;)

Who is online

Users browsing this forum: No registered users and 1 guest