[英]In my UWP application ComboBox, PointerExited event fired right after we click on the control when IsEditable is False
There seems to be a similar question but it is not resolved.似乎有一个类似的问题,但它没有解决。
I am using a ComboBox in my WinRT/C++ application and need to show the cursor as Hand while hovering over it.我在我的 WinRT/C++ 应用程序中使用 ComboBox 并且需要将 cursor 显示为手,同时将鼠标悬停在它上面。 The issue is that while clicking on it, the cursor turns to arrow since PointerExited is fired.问题是,当点击它时,cursor 会变成箭头,因为 PointerExited 被触发。 I had added code to change cursor to Hand when "PointerEntered" and arrow when "PointerExited".我添加了代码以在“PointerEntered”时将 cursor 更改为 Hand 并在“PointerExited”时更改箭头。
This issue is seen only when IsEditable is set as False.仅当 IsEditable 设置为 False 时才会出现此问题。 When the bool flag is True, it works as expected.当 bool 标志为 True 时,它按预期工作。
I wish to workaround this unnecessary PointerExited firing, ie, as long as I'm in the combobox area I want to show "Hand".我希望解决这种不必要的 PointerExited 触发,即,只要我在 combobox 区域,我想显示“手”。
The Combobox is made of two main parts. Combobox 由两个主要部分组成。 One is a ContentPresenter
that shows the selected item, another is a PopUp
that shows the items.一个是显示所选项目的ContentPresenter
,另一个是显示项目的PopUp
。 The PointerEntered event you are handling belongs to the ContentPresenter
part.您正在处理的PointerEntered事件属于ContentPresenter
部分。 When you click the Combobox and the PopUp
overlays on the ContentPresenter
part, the PointerExited will be fired because the cursor is entering the PopUp
.当您单击 Combobox 和ContentPresenter
部分上的PopUp
覆盖时, PointerExited将被触发,因为 cursor 正在进入PopUp
。 Currently, there is no way to avoid this behavior.目前,没有办法避免这种行为。
There is no perfect solution for this.对此没有完美的解决方案。 A workaround is that you could handle the PointerEntered event of the ScrollViewer
which is inside the PopUp
.一种解决方法是您可以处理PopUp
内部的ScrollViewer
的PointerEntered事件。 Change the cursor type into hands in that event like what you did in the PointerEntered event and **PointerExited ** event of the Combobox
.在该事件中将 cursor 类型更改为手,就像您在 Combobox 的PointerEntered事件和 **PointerExited ** 事件中Combobox
的那样。
Please check the following steps:请检查以下步骤:
ComboBox
control from generic.xaml file and apply the style to your ComboBox
control.从 generic.xaml 文件中获取ComboBox
控件的默认样式并将该样式应用于您的ComboBox
控件。ScrollViewer
control in the added style, and add event handlers for PointerEntered event and PointerExited event.在添加的样式中找到ScrollViewer
控件,并为PointerEntered事件和PointerExited事件添加事件处理程序。This is the basic steps, you might need to check other logic like selected item changes to make sure the cursor is in the correct type in such scenarios.这是基本步骤,您可能需要检查其他逻辑,如所选项目更改,以确保 cursor 在此类情况下处于正确的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.