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

Dani_S 3,336 Reputation points
2023-04-24T17:26:17.13+00:00

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

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

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 29,381 Reputation points Microsoft Vendor
    2023-04-25T05:33:25.0133333+00:00

    Hello,

    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));
                    });
                };                  
    #endif
            });
    

    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