我是一个WPF/XAML新手,所以这可能是一个非常明显的问题。
我在我的项目中添加了一个FlowDocument类型的新项。让我们称它为CrappyFlowDocument.xaml
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
ColumnWidth="400" FontSize="14" FontFamily="Georgia">
<Paragraph>
Woo, my first paragraph!
</Paragraph>
</FlowDocument>我把它放在一个单独的文件中,因为我想避免在我的PrettyInfoWindow中间放一大堆文本。
现在,在我的PrettyInfoWindow中,我被难住了。
<FlowDocumentScrollViewer x:Name="flowDocViewer" Margin="0,0,0,0" Background="#FF414141" Zoom="80" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled" IsSelectionEnabled="False">
<!-- What do I put here-abouts to get my CrappyFlowDocument.xaml to show? -->
</FlowDocumentScrollViewer>我在网上找不到任何关于这种“包含”功能的东西,但可能我的搜索结果很糟糕。如果这不是FlowDocument.xaml文件的预期用途,那么什么才是呢?
发布于 2010-12-15 16:34:04
下面是我会怎么做:
首先,通过向CrappyFlowDocument添加一个键并将其放入资源字典,使其成为资源:
在App.xaml中:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CrappyFlowDocument.xaml" />
</ResourceDictionary>
</Application.Resources>
在CrappyFlowDocument.xaml文件中:
<ResourceDictionary>
<FlowDocument x:Key="MyCrappyFlowDoc"
ColumnWidth="400"
FontSize="14"
FontFamily="Georgia">
<Paragraph>
Woo, my first paragraph!
</Paragraph>
</FlowDocument>
</ResourceDictionary>然后,将其作为FlowDocumentScrollViewer的"Document“属性直接调用:
<FlowDocumentScrollViewer Margin="0,0,0,0"
Background="#FF414141"
Zoom="80"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Disabled"
IsSelectionEnabled="False"
Document="{StaticResource MyCrappyFlowDoc}" />我不知道有什么更简单的方法可以做到这一点,希望这能满足你的需要
https://stackoverflow.com/questions/4438319
复制相似问题