UWP RichEditBox:如何为加载的 RTF 文件启用超链接 (Document.LoadFromStream)

UWP RichEditBox: How to enable HyperLinks for loaded RTF files (Document.LoadFromStream)

XAML:

<ScrollViewer x:Name="RtfEulaViewer" Grid.Row="1" VerticalAlignment="Top">
    <RichEditBox x:Name="RtfEula" IsHitTestVisible="False" IsFocusEngagementEnabled="False" IsReadOnly="True" 
         Background="{ThemeResource StandardBackground}" BorderThickness="0" TextWrapping="Wrap" />
</ScrollViewer>

代码:

StorageFile file = await StorageFile.GetFileFromPathAsync(filePath);
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
this.RtfEula.Document.LoadFromStream(TextSetOptions.FormatRtf, stream);

用 Word 或写字板打开时可点击的 RTF 文件中的绝对或相对超链接仅显示为普通文本。

{\field{\*\fldinst HYPERLINK "http://www.microsoft.com"}{\fldrslt Microsoft}}

RTF 规范显示为蓝色,但也处于非活动状态。鼠标移过去,鼠标指针不会改变。

有没有办法在加载 RTF 文件时在某些文本框中获取活动的超链接?

在您的代码中,您设置了 IsHitTestVisible="False"。这将禁用所有输入交互。这就是为什么您的 hyper link 不可点击。删除此设置或将其值更改为 True 应该可以解决您的问题。

<RichEditBox x:Name="RtfEula" IsFocusEngagementEnabled="False" IsReadOnly="True" 
     Background="{ThemeResource StandardBackground}" BorderThickness="0" TextWrapping="Wrap" />