最简单的解决方案可能是将FlowDocument放在资源字典中,然后像这样使用x:Key
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FlowDocument x:Key="myFlowDocument" ..>
</FlowDocument>
</ResourceDictionary>
<FlowDocumentScrollViewer Name="flowDocumentScrollViewer">
<StaticResource ResourceKey="myFlowDocument"/>
</FlowDocumentScrollViewer>
否则,您将不得不设置流文档来构建操作嵌入资源,并将其以如下方式隐藏在代码后面
Stream flowDocumentStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DocumentNameSpace.FlowDocumentName.xaml");
FlowDocument flowDocument = (FlowDocument)XamlReader.Load(flowDocumentStream);
flowDocumentScrollViewer.Document = flowDocument;
更新