Anton Kalcik
Anton Kalcik

Reputation: 2206

MouseLeave event in Silverlight 3 PopUp control

I want use PopUp (System.Windows.Controls.Primitives.PopUp) control to show some context menu. After mouse leaves, should automatically close. But eventhandler for MouseLeave is never executed. Why?

SAMPLE:

void DocumentLibrary_Loaded(object sender, RoutedEventArgs e)
{
    DocumentLibraryDialog documentLibraryDialog = new DocumentLibraryDialog();

    _popUpDocumentLibraryDialog = new Popup();
    _popUpDocumentLibraryDialog.Width = 70;
    _popUpDocumentLibraryDialog.Height = 20;
    _popUpDocumentLibraryDialog.MouseLeave += new MouseEventHandler(_popUpDocumentLibraryDialog_MouseLeave);
    _popUpDocumentLibraryDialog.Child = documentLibraryDialog; 
}

void _popUpDocumentLibraryDialog_MouseLeave(object sender, MouseEventArgs e)
{
    Popup currentPopUp = (Popup)sender;
    if (currentPopUp.IsOpen)
        (currentPopUp.IsOpen) = false;
}

Regards

Anton Kalcik

Upvotes: 2

Views: 1686

Answers (2)

Narutokk
Narutokk

Reputation: 1034

you have to bind the event on the Popup.Child, instead of popup itself, it may be a bug of silverlight.

Upvotes: 1

kmontgom
kmontgom

Reputation: 1429

What type of child controls are in the Popup? In other circumstances with WPF/Silverlight, I've had child controls swallow messages that it would have been nice for the parent to handle.

As an experiment, what happens if you attach MouseLeave handlers for child controls?

Upvotes: 1

Related Questions