这是一个将链接单击事件添加到 RichEditBox 的助手:
public class LinkClickedEventArgs
{
public string LinkText { get; set; }
}
public class RichEditBoxWithHyperlink :RichEditBox
{
public event EventHandler<LinkClickedEventArgs> LinkClicked;
protected override void OnTapped(TappedRoutedEventArgs e)
{
base.OnTapped(e);
if (LinkClicked != null)
{
Point tappedPoint = e.GetPosition(this);
ITextRange textRange = this.Document.GetRangeFromPoint(tappedPoint, PointOptions.ClientCoordinates);
textRange.StartOf(TextRangeUnit.Link,true);
if (!string.IsNullOrEmpty(textRange.Link))
{
LinkClicked(this, new LinkClickedEventArgs(){LinkText = textRange.Link});
}
}
}
}