[英]How to catch hyperlink clicks in UWP RichEditBox?
我正在尝试在 UWP 自定义组件中使用 RichEditBox,该组件将通过 XamlIslands 添加到 WPF 应用程序:
<RichEditBox x:Name="editor" PointerPressed="editor_PointerPressed" Tapped="editor_Tapped" PointerReleased="editor_PointerPressed">
我通过以下方式添加超链接:
editor.Document.Selection.Link = "\"[the link]\"";
它工作正常,当 Ctrl+Click 时它会在浏览器中打开链接,但是我怎样才能捕捉到该点击事件呢?
我在 RichEditBox 中定义为参数的回调均未触发,因此根本不会触发 PointerPressed、PointerReleased 和 Tapped 事件。
如何在 UWP RichEditBox 中捕获超链接点击?
恐怕您无法检测到超链接点击事件,目前还没有可以检测到点击动作的 api,如果您确实需要此功能,请使用 windows 反馈中心应用程序发布您的要求。
我设法这样做:
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.