2

Maybe this is a stupid question, but how can I click (and capture the click event of) a link in a Windows 8 RichEditBox.

I've placed the link using RichEditBox.Document.GetRange(0, 10).Link = "\"foobar\"". The link itself is shown in the RichEditBox, but I can't click it.

Thanks for advices.

4

2 回答 2

6

这是一个将链接单击事件添加到 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});
            }
        }
    }
}
于 2013-09-13T17:37:01.013 回答
0

RichEditBox缺少 WPF 的RichTextBox事件LinkClicked。无法检测链接是否被点击。您只能通过ctrl点击链接来打开超链接。

如何使超链接在 RichTextBox 中工作?- 这是 WPF 中的内容

于 2013-09-13T16:38:56.193 回答