简体   繁体   中英

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. The issue is that while clicking on it, the cursor turns to arrow since PointerExited is fired. I had added code to change cursor to Hand when "PointerEntered" and arrow when "PointerExited".

This issue is seen only when IsEditable is set as False. When the bool flag is True, it works as expected.

I wish to workaround this unnecessary PointerExited firing, ie, as long as I'm in the combobox area I want to show "Hand".

The Combobox is made of two main parts. One is a ContentPresenter that shows the selected item, another is a PopUp that shows the items. The PointerEntered event you are handling belongs to the ContentPresenter part. 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 . 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 . Change the cursor type into hands in that event like what you did in the PointerEntered event and **PointerExited ** event of the Combobox .

Please check the following steps:

  1. Get the default style of ComboBox control from generic.xaml file and apply the style to your ComboBox control.
  2. Find the ScrollViewer control in the added style, and add event handlers for PointerEntered event and PointerExited event.
  3. Change the cursor type in the handlers.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM