2009-09-19 152 views
2

我想使用PopUp(System.Windows.Controls.Primitives.PopUp)控件来显示一些上下文菜单。鼠标离开后,应该自动关闭。但MouseLeave事件处理程序永远不会执行。为什么?Silverlight 3中的MouseLeave事件PopUp控件

示例:

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; 
} 

问候

安东Kalcik

回答

1

什么类型的子控件的是,在弹出的?在WPF/Silverlight的其他情况下,我已经有了子控件吞下消息,这对父进程来说是很好的。

作为一个实验,如果您为子控件附加MouseLeave处理程序会发生什么?

+0

这是我的解决方案。我将MouseLeave处理程序连接到子容器。关于AKA – 2009-11-16 14:37:07

1

你必须绑定Popup.Child上的事件,而不是弹出自身,它可能是silverlight的一个bug。

相关问题