In my silverlight project I have a Menu, that I want to close it if I click anywhere outside it. I add handler to the click event on App:
AddHandler App.Current.RootVisual.MouseLeftButtonDown, AddressOf HideMenu
But the problem that: it does not enter the Handler when I click on any other command, or click on the same control that have the context menu, it is enter only when I click on an empty area outside the menu.
Thanks.
I wasn't aware that was a signature of
AddHandler
that only takes 2 parameters, perhaps its a VB thing that you are getting away with it and its defaulting the third parameter toFalse
. This parameter is the handledEventsToo parameter which indicates you want your handler to execute even when some other control has handled the event.I guess the VB would look like this:-
Edit
Lets ditch this VB code which is wrong anyway. Here is what the code should look like in C# (you must be fairly familar with translating since the vast majority of code examples on the Web for silverlight will be in C#).
Where this code is in the code behind of the containing UserControl and
HideMenu
has this signature:-