简体   繁体   中英

How to catch hyperlink clicks in UWP RichEditBox?

I'm trying to use RichEditBox in a UWP custom component, which would be added to a WPF application through XamlIslands:

<RichEditBox x:Name="editor" PointerPressed="editor_PointerPressed" Tapped="editor_Tapped" PointerReleased="editor_PointerPressed">

I add hyperlinks with the following way:

editor.Document.Selection.Link = "\"[the link]\"";

It works fine and it opens the link in the browser when Ctrl+Click on it, but how can I catch that click event?

None of the callbacks are fire which I defined as a parameter in RichEditBox, so no PointerPressed, no PointerReleased, and no Tapped events are fired at all.

How to catch hyperlink clicks in UWP RichEditBox?

I'm afraid you can't detect the hyperlink click event, currently, there is no such api that could detect click action, if you do want this feature, please feel post your requirement with windows feed back hub app.

I managed to do it like this:

   public class CustomRichTextBox: RichEditBox
{
    protected override void OnTapped(TappedRoutedEventArgs e)
    {
        base.OnTapped(e);

        var tappedPoint = e.GetPosition(this);
        var textRange = Document.GetRangeFromPoint(tappedPoint, PointOptions.ClientCoordinates);
        textRange.StartOf(TextRangeUnit.Link, true);

        var mylink = textRange.Link;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM