代码之家  ›  专栏  ›  技术社区  ›  Christian

如何在Xamarin中更改鼠标光标。将鼠标悬停在超链接上时的窗体?

  •  0
  • Christian  · 技术社区  · 6 年前

    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>
    

    0 回复  |  直到 6 年前
        1
  •  2
  •   MatVic    5 年前

    [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;
            }
        }
    }