【发布时间】:2018-11-20 19:19:58
【问题描述】:
我正在使用 CustomRenderer 将标签文本作为超链接。我的代码标签显示带下划线,我们正在使用 Label.GestureRecognizers 来捕获点击。但是鼠标光标悬停在超链接文本上后没有显示手。
下面是我们正在使用的代码:
共享项目:
- HyperlinkLabel.cs:
namespace HyperlinkLabelControl
{
public class HyperLinkLabel : Label
{
}
}
- MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:HyperlinkLabelControl"
x:Class="HyperlinkLabelControl.MainPage">
<ContentPage.Content>
<StackLayout>
<local:HyperlinkLabel Text="MyHyperLinkLabel" >
<Label.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding BindingContext.MyClickedCommand, Source={x:Reference List}}"
CommandParameter="{Binding .}" />
</Label.GestureRecognizers>
</local:HyperlinkLabel>
</StackLayout>
</ContentPage.Content>
</ContentPage>
UWP 项目:
- HyperLinkLabelRenderer.cs:
[assembly: ExportRenderer(typeof(HyperLinkLabel), typeof(HyperLinkLabelRenderer))]
namespace HyperlinkLabelControl.UWP.Renderers
{
public class HyperLinkLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
Control.TextDecorations = TextDecorations.Underline;
}
}
}
请提供鼠标光标在 Xamarin 中悬停在超链接文本上后显示手的方法。
【问题讨论】:
标签: xaml xamarin xamarin.forms uwp