Silverlight Handle App MouseLeftButtonDown?
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 ente开发者_开发百科r 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 to False
. 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:-
AddHandler App.Current.RootVisual.MouseLeftButtonDown, AddressOf HideMenu, True
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#).
this.AddHandler(UIElement.MouseLeftButtonDownEvent, HideMenu, true);
Where this code is in the code behind of the containing UserControl and HideMenu
has this signature:-
void HideMenu(object sender, MouseEventArgs e)
{
}
精彩评论