【问题标题】:How to catch hyperlink clicks in UWP RichEditBox?如何在 UWP RichEditBox 中捕获超链接点击?
【发布时间】:2021-04-19 05:47:40
【问题描述】:

我正在尝试在 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 事件。

【问题讨论】:

    标签: uwp richeditbox xaml-islands


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      我设法做到了:

         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;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2013-09-18
        • 2011-01-08
        • 2017-08-15
        • 1970-01-01
        • 2014-02-25
        • 1970-01-01
        • 2012-09-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多