将鼠标悬停在超链接上时,如何更改 Xamarin.forms 中的鼠标光标?

How do I change the mouse cursor in Xamarin.forms when hovering over a hyperlink?

Xamarin.forms 3.3.0 update 中,建议通过以下方式创建超链接:

<Label>
    <Label.FormattedText>
        <FormattedString>
            <FormattedString.Spans>
                <Span Text="This app is written in C#, XAML, and native APIs using the" />
                <Span Text=" " />
                <Span Text="Xamarin Platform" FontAttributes="Bold" TextColor="Blue" TextDecorations="Underline">
                    <Span.GestureRecognizers>
                       <TapGestureRecognizer 
                            Command="{Binding TapCommand, Mode=OneWay}"
                            CommandParameter="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/"/>
                     </Span.GestureRecognizers>
                </Span>
                <Span Text="." />
            </FormattedString.Spans>
        </FormattedString>
    </Label.FormattedText>
</Label>

通常,在 Windows 上,鼠标光标悬停在超链接上时会发生变化。在 Xamarin.forms 中有没有办法获得相同的鼠标 courser 更改?

我认为您可以为 UWP 创建自定义渲染器。 例如,像这样:

[assembly: ExportRenderer(typeof(HyperLinkLabel), typeof(HyperLinkLabel_UWP))]
namespace MyApp.UWP.CustomRenders
{
    public class HyperLinkLabel_UWP: LabelRenderer
    {
        private readonly Windows.UI.Core.CoreCursor OrigHandCursor = Window.Current.CoreWindow.PointerCursor;

        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null)
            {
                Control.PointerExited += Control_PointerExited;
                Control.PointerMoved += Control_PointerMoved;
            }
        }

        private void Control_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreCursor handCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 1);
            if (handCursor != null)
                Window.Current.CoreWindow.PointerCursor = handCursor;
        }

        private void Control_PointerExited(object sender,     Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (OrigHandCursor != null)
                Window.Current.CoreWindow.PointerCursor = OrigHandCursor;
        }
    }
}