1

我正在尝试在 UWP 自定义组件中使用 RichEditBox,该组件将通过 XamlIslands 添加到 WPF 应用程序中:

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

我通过以下方式添加超链接:

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

它工作正常,当 Ctrl+单击它时它会在浏览器中打开链接,但我怎样才能捕捉到该单击事件?

我在 RichEditBox 中定义为参数的回调都不会触发,因此根本不会触发 PointerPressed、PointerReleased 和 Tapped 事件。

4

2 回答 2

0

我设法这样做:

   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;
    }
}
于 2022-01-21T09:10:41.480 回答
0

如何在 UWP RichEditBox 中捕获超链接点击?

恐怕你无法检测到超链接点击事件,目前还没有这样的 api 可以检测点击动作,如果你确实想要这个功能,请用 windows 反馈中心应用程序发布你的要求。

于 2021-01-14T13:24:09.913 回答