- Я думаю, вы могли бы использовать
TapGestureRecognizer
и удалить тег привязки, преобразовав связанный текст, это может быть намного проще при использовании пользовательского представления. Добавьте привязываемое свойство для текста ссылки и другое для команды навигации.
CustomView.Xaml
<ContentView.Content>
<Label x:Name="linkTextLabel"/>
</ContentView.Content>
CustomView.Xaml.cs
public string TextWithlink
{
get { return (string)GetValue(TextWithlinkProperty); }
set
{
SetValue(TextWithlinkProperty, value);
}
}
public static readonly BindableProperty TextWithlinkProperty = BindableProperty.Create("TextWithlink", typeof(string), typeof(LinkText), "", BindingMode.Default, propertyChanged: OnTextLinkChanged);
public Command NavigationCommand
{
get { return (Command)GetValue(NavigationCommandProperty); }
set
{
SetValue(NavigationCommandProperty, value);
}
}
public static readonly BindableProperty NavigationCommandProperty = BindableProperty.Create("NavigationCommand", typeof(Command), typeof(LinkText), null, BindingMode.Default, propertyChanged: OnNavigationCommandChanged);
private static void OnNavigationCommandChanged(BindableObject bindable, object oldvalue, object newValue)
{
(bindable as LinkText).ChangeCommand();
}
private static void OnTextLinkChanged(BindableObject bindable, object oldvalue, object newValue)
{
(bindable as LinkText).Changetext();
}
private void ChangeCommand()
{
linkTapGesture = new TapGestureRecognizer();
linkTapGesture.Command = this.NavigationCommand;
linkSpan.GestureRecognizers.Clear();
linkSpan.GestureRecognizers.Add(linkTapGesture);
}
private void Changetext()
{
FormattedString formattedString = new FormattedString();
/// String formatting code, change according to your need
string[] subStrings = this.TextWithlink.Split('<');
Span textSpan = new Span()
{
Text = subStrings[0] + " "
};
string linkString = subStrings[1].Split('>')[1];
linkSpan = new Span()
{
Text = linkString,
};
///
formattedString.Spans.Add(textSpan);
formattedString.Spans.Add(linkSpan);
this.linkTextLabel.FormattedText = formattedString;
}
Использование. Xaml
<local:LinkText
TextWithlink="{Binding TextWithLink}" NavigationCommand="{Binding NavigationCommand}"/>
Но если вы хотите, чтобы приложение перемещалось по гиперссылке. Поскольку перенаправления ссылок обрабатываются мобильной ОС, рассмотрим пользовательские перенаправления URI. Этот
блог может помочь вам.
Для Android, глубокая ссылка
Для iOS, пользовательский URI
ИМХО навигация по URI могла бы быть немного больше работы для навигации внутри приложения.