-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Cursor when hovering over View on Desktop #4552
Comments
We can probably use https://developer.apple.com/documentation/appkit/nstrackingarea |
I encourage the MAUI team to think beyond desktop for this. iPadOS also supports customizing cursors, albeit in a more focused way. E.g. https://developer.apple.com/documentation/uikit/uipointershape/roundedrect_radius Android also has a cursor API https://developer.android.com/reference/android/view/PointerIcon |
I think MAUI must cover all things, desktop and mobiles/tablets environments. I saw a lot of "tutorials" on youtube with MAUI, but most of them are for android environment! Why they (we) have to think of MAUI only to mobile devices as long as it was made for desktop, mobile and now TV OSes? |
Assuming for the moment the app developer knows the pointer has entered or exited the area occupied by a specific control, can the mouse cursor actually be changed in Maui? For example, SkiaSharp does provide enough information to know when you want to change the cursor, but how do you actually change the cursor? |
for Windows i currently use the following Extension method to change the cursor public static void ChangeCursor(this UIElement uiElement, InputCursor cursor)
{
Type type = typeof(UIElement);
type.InvokeMember("ProtectedCursor", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty | BindingFlags.Instance, null, uiElement, new object[] { cursor });
} it can be called like this (for example in the myUIElement.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Hand)); on macOS it's even easier - i'm using
|
Cursors are relatively easy to set on MacCatalyst as well:
However the problem is, the selection of cursor types is limited on MacCatalyst compared to AppKit. For example, there is no It's trivial to access these 'unsupported' API's via C# code:
But this is not something we are currently comfortable adding to the core MAUI product. We have no reason to believe Apple will reject MacCatalyst app store submissions which use API's officially supported on AppKit, but not officially supported on MacCatalyst, and there is reasonable evidence if you search, to suggest many apps are shipping to the store with these types of API usages. But we also don't want to add implicitly agreed to risk to our customers by adding this code to MAUI. For now, I'd suggest writing a simple service that can handle mouse cursors on each of the platforms you're interested in, and deciding if you want to leverage these unsupported API's on MacCatalyst or not yourself so that you are in control if something changes with Apple's decisions around appstore submissions in this area. |
@jamesmontemagno, @jfversluis, and @davidortinau, I see I'm not the only one who feels that the MAUI team has relegated Desktop to the back burner... |
Thanks for this @nor0x !! It was really helpful! (P.S. Mentioning how you convert the MAUI elements to UIElement could have been a plus but figured that out anyways :) |
Thanks for this!!!
…On Sun, Feb 19, 2023 at 10:50 PM Shivji Bhagat ***@***.***> wrote:
for Windows i currently use the following Extension method to change the
cursor
public static void ChangeCursor(this UIElement uiElement, InputCursor cursor)
{
Type type = typeof(UIElement);
type.InvokeMember("ProtectedCursor", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty | BindingFlags.Instance, null, uiElement, new object[] { cursor });
}
it can be called like this (for example in the EventHandler of a
PointerGestureRecognizer)
myUIElement.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Hand));
on macOS it's even easier - i'm using
NSCursor.PointingHandCursor.Set();
Thanks for this @nor0x <https://github.com/nor0x> !! It was really
helpful, after not getting anything in the official docs!
—
Reply to this email directly, view it on GitHub
<#4552 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOPRYYPVR5IYSXZPCEPU3Z3WYMH5FANCNFSM5NZF5YJA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
about getting the void PointerEntered(object sender, Microsoft.Maui.Controls.PointerEventArgs e)
{
if (sender is Label label)
{
#if WINDOWS
if (label.Handler.PlatformView is Microsoft.UI.Xaml.Controls.TextBlock textBlock)
{
textBlock.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Hand));
}
#endif
#if MACCATALYST
NSCursor.PointingHandCursor.Set();
#endif
}
} |
I agree with that, providing the ability to change the mouse cursor when hovering over a view can be a useful feature for desktop apps, as it can help to provide visual feedback to users and guide their interactions with the application. |
There is also https://github.com/VladislavAntonyuk/MauiSamples/tree/main/MauiCursor by @VladislavAntonyuk for all platforms. |
This is still reproducible on blazor hybrid (maui) with .net 8, "cursor:pointer" css is not taking any effect. |
@orosbogdan said:
For CSS it's up to each platform's native webview whether it supports certain CSS properties. I couldn't find any From my test just now with WebView2:
Interestingly, many of these seem to work fine in Edge itself, but not in Edge WebView2. Not sure why that is. But there's this WebView2 bug filed to track that: MicrosoftEdge/WebView2Feedback#2766. I added some additional info there about my testing and the current status. So as far as WebView/BlazorWebView is concerned, this issue is up to each platform's own native WebView, and I don't think any further action is requried within .NET MAUI. But this bug should remain open to track support for native UI (as opposed to web UI). |
I think by |
Right, my bad, I meant cursor:pointer. |
On Desktop platforms, when hovering over a view, provide the ability to change the mouse cursor.
Could we provide this via an attached property, or perhaps provide an out of the box behaviour for this?
The API should provide a way to select and set one of the available system cursor types when the mouse/pointer is over a view. This could be an enum of cursor values.
Notes:
The text was updated successfully, but these errors were encountered: