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.