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

标签 c# xaml hyperlink uwp rtf

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

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

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

来自 RTF 规范,以蓝色显示,但也处于非事件状态。如果我移动到它上面,鼠标指针不会改变。

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

最佳答案

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

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

关于c# - UWP RichEditBox : How to enable HyperLinks for loaded RTF files (Document. LoadFromStream),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44280937/

相关文章:

c# - SSIS 从 http 下载 - 从服务器获取的错误 SSL 证书响应无效

c# - 属性 'x' 不是实体类型 'y' 的导航属性

c# - Windows Mobile 应用程序中的密码学

WPF 使用自定义 RoutedUICommands 还是简单的事件处理程序?

c# - 如何在Xaml中为使用mvvm代码创建的窗口添加样式?

c# - 在 Xamarin.Forms 中以编程方式引发控件事件

以 "vscode:"开头的 HTML 链接,用于在 Visual Studio Code 中打开文件

excel - 试图从 "Main"表自动添加超链接到新的自动化表?

c# - 防止 Excel 在 C# 中更新屏幕

Java PDF 操作,基于模式匹配替换文本,带有超链接