microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.32k stars 677 forks source link

Protected cursor is not working in WinUI3 Combox Items. #9023

Open Ajith-GS opened 11 months ago

Ajith-GS commented 11 months ago

Describe the bug

Not able to change cursor on ComboBoxItems in a WinUI 3 application using API ProtectedCursor(). Tried to set cursor to “Hand cursor” using ProtectedCursor in ComboBox Loaded and ComboBoxItem Loaded events.

Steps to reproduce the bug

  1. Create a C++ WinUI3 project using "Blank App, Packaged (WinUI 3 in Desktop)" template.
  2. Make it Unpackaged application using the step mentioned in the following link. https://learn.microsoft.com/en-us/windows/apps/winui/winui3/create-your-first-winui3-app#unpackaged-create-a-new-project-for-an-unpackaged-c-or-c-winui-3-desktop-app
  3. Add ComboBox control in xaml and subscribe the loaded event of both ComboBox and ComboBoxItem. Call ChangeCursor function from the loaded event handlers as shown below:-
ComboBox_Loaded(winrt::Windows::Foundation::IInspectable` const& sender, 
     winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
    UNREFERENCED_PARAMETER(e);
    ChangeCursor(sender);
}

ComboBoxItem_Loaded(winrt::Windows::Foundation::IInspectable const& sender, 
     winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
    UNREFERENCED_PARAMETER(e);
   ChangeCursor(sender);
}

ChangeCursor(winrt::Windows::Foundation::IInspectable const& controlObj)
{
    Microsoft::UI::Xaml::UIElement controlElement = NULL;
    if (nullptr != controlObj)
    {
        controlElement = controlObj.as<Microsoft::UI::Xaml::UIElement>();

        Microsoft::UI::Input::InputCursor cursorObj = NULL;
        cursorObj = winrt::InputSystemCursor::Create(winrt::InputSystemCursorShape::Hand);

        if ((nullptr != controlElement) && (nullptr != cursorObj))
        {
            controlElement.ProtectedCursor(cursorObj);
        }
    } 
}
  1. Build the application.
  2. Run the application in Visual Studio.
  3. Verify that the cursor changes from “Arrow” to “Hand” when pointer moved above ComboBox down arrow button.
  4. Open the ComboBox DropDown.
  5. Mouse hovering through DropDown Items.

Expected behavior

The cursor should be Hand while hovering through items.

Screenshots

No response

NuGet package version

Windows App SDK 1.4.2: 1.4.231008000

Packaging type

Unpackaged

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

A sample application with given issue is attached TestApp_Combobox_CursorChange_Issue.zip

Any help is greatly appreciated. Thank you.

Ajith-GS commented 10 months ago

Is there any update on above issue? same issue occurred in Popup control, MenuFlyoutItem etc

Ajith-GS commented 6 months ago

The problem also exists in the most recent version of Windows App SDK 1.5 (1.5.240311000). This implementation was working fine till WinAppSDK1.3.