ComboBox 未按预期引发键盘和鼠标事件
我使用 Silverlight 4.0,并且在使用 ComboBox 控件时遇到问题。我想实现一个弹出菜单,无需单击鼠标即可显示和隐藏自身。当我将光标放在其区域上时,它应该显示 - 这个 prt 运行良好。然后,只要鼠标指针放置在其区域之外一段时间,它就应该隐藏。我用 MouseEnter 和 MouseLeave 事件来实现它。 我的问题是 ComboBox - 在我看来,这个控件的行为很奇怪。通常,当我将光标放在它上面时,我希望它引发 MouseEnter 事件,当我将鼠标光标放在其他地方时,它会引发 MouseLeave 事件。真实情况有所不同:每当我单击组合框时,它都会打开并显示选项列表,并立即发送 LostFocus 和 MouseLeave 事件。因此,看起来控件失去了键盘焦点,鼠标指针已移出其区域,而实际上选择的组合框列表已打开并处于活动状态,并且其中有键盘焦点。
所以问题是我如何知道我的程序中组合框中发生了什么?为了正确隐藏我的弹出菜单,我需要知道组合框中的选项列表何时打开或关闭。我看不到此文档或任何其他文档的任何事件。 (想要的行为是:如果组合框关闭,我会根据鼠标光标的位置隐藏弹出菜单。如果组合框打开,我永远不会隐藏弹出菜单,直到用户在组合框中选择某些内容或关闭组合框。 )
此外,如果您对第三方组合框替代品有良好的体验,其外观和工作方式类似并且引发我需要的事件,请告诉我。
I use Silverlight 4.0 and have got problems with ComboBox control. I want to implement a popup menu which will show and hide itself without clicking mouse. It should show when I place cursor on its region - this prt works well. Then it should hide whenever mouse pointer is placed outside of its region for a while. I implemented it with MouseEnter and MouseLeave events. My problem is ComboBox - this control behaves weirdly, in my opinion. Normally I would expect it to raise MouseEnter event when I put the cursor on it and MouseLeave when I put the mouse cursor anywhere else. The real situation is different: Whenever I click the combobox, it opens and shows the list of options, and immediately sends LostFocus and MouseLeave events. So it seems like the control lost keyboard focus and mouse pointer has been moved out of its region, while actually the combobox list of optins is open and active and has keyboard focus in it.
So the question is how can I know in my program what is happening in comboboxes? In order to correctly hide my popup menu, I need to know when the list of options in a combobox is open or closed. I can't see any events for this or any other documentation. (Wanted behavior is: If a combobox is closed, I hide my popup menu based on the position of mouse cursor. If a combobox is open, I never hide my popup menu until user either selects something in the combobox, or closes the combobox.)
Also, if you have got a good experience with a third party combobox replacement, which looks and works similarly AND raises events I need, please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSDN 为 ComboBox 列出了两个事件,您可能需要查看。
http://msdn。 microsoft.com/en-us/library/system.windows.controls.combobox_events(v=VS.95).aspx
DropDownClosed 下拉菜单时发生组合框的一部分关闭。
DropDownOpened 当组合框的下拉部分打开时发生。
MSDN has two events listed for ComboBox that you might want to look at.
http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox_events(v=VS.95).aspx
DropDownClosed Occurs when the drop-down portion of the combo box closes.
DropDownOpened Occurs when the drop-down portion of the combo box opens.