簡體   English   中英

如何捕捉 UWP RichEditBox 中的超鏈接點擊?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM