Reputation: 149
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.
Upvotes: 2
Views: 431
Reputation: 3345
Here is a helper to add a link clicked event to the 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});
}
}
}
}
Upvotes: 6
Reputation: 15296
RichEditBox
lacks WPF's RichTextBox
's LinkClicked
event. There is no way to detect whether the link was clicked or not. You can open the hyperlink only by pressing ctrl and clicking on link.
How can I make a hyperlink work in a RichTextBox? - This what in WPF
Upvotes: 0