Maui - hover button -hand like in css in net 6 using a global handler mapping

Dani_S 3,106 Reputation points

Hi, If possible to create sample of hover button -hand like in css in net 6 using a global handler mapping?

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,078 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 28,071 Reputation points Microsoft Vendor


    This thread is an extra question of Maui - hover button I see hand like in css. Your main purpose is to know if you don't need to add the code for each button in app.

    You can find the VirtualView and customize the Cursor in handler mapping.

    (You cannot set ProtectedCursor until the Visual Tree is loaded. It's the limitation in WinUI, see Changing the mouse cursor in WinUI 3 #1816)

    Microsoft.Maui.Handlers.ButtonHandler.Mapper.AppendToMapping("Custom", (handler, view) =>
    #if WINDOWS
                Button button = handler.VirtualView as Button;
                button.Loaded += (sender, args) =>
                    Microsoft.UI.Xaml.Controls.Button btn = (Microsoft.UI.Xaml.Controls.Button)handler.PlatformView;
                    MainThread.BeginInvokeOnMainThread(() =>
                        ElementExtension.ChangeCursor(btn, InputSystemCursor.Create(InputSystemCursorShape.Hand));

    Best Regards,

    Wenyan Zhang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful