c# - 使用字符串创建流文档

标签 c# wpf xaml flowdocument flowdocumentscrollviewer

我有一些文本正在从数据库中读取。此文本是 xaml 部分对象的字符串表示形式。此文本将根据组合框中的选择而有所不同。这是一些文本的示例:

<Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Verdana" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="11" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0"><Paragraph><Run>Hello World      </Run></Paragraph></Section>

我需要获取此文本并在应用程序的控件中以正确的格式显示它。我相信,为了做到这一点,我需要一个 FlowDocumentViewer(我正在使用 FlowDocumentScrollViewer)。

我想不通的是如何将文本放入流文档中,以便我可以将它与文档查看器相关联(绑定(bind))(我是这方面的菜鸟)。

有人能帮忙吗?

最佳答案

您可以使用 XamlReader.Parse从字符串创建一个 Section,然后您可以将其添加到文档中。

关于c# - 使用字符串创建流文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9402785/

相关文章:

c# - 如何在 C# 中使用由 MATLAB 编译的 C++ DLL

c# - 如何在不覆盖现有样式的情况下向 WPF 自定义控件添加触发器?

wpf - 取消 WPF 中验证错误时的 TextBox 输入

wpf - 无法命令将切换按钮绑定(bind)为控件模板

c# - 使用 MVVM 模式的 UI 设计

forms - 将 ViewModel 绑定(bind)到 Prism.Forms 中的 XAML View

Java通过JNI转C#无法加载C# dll

c# - 自定义用户控件未显示在列表框中

c# - 简单的 linq 查询会出现错误

c# - 新 WPF 窗口仅显示在原始窗口下方