开发者

Bind FlowDocument to my FlowDocumentScrollViewer

I'm a bit of a WPF/XAML newbie, so it is probably a very obvious question.

I added a new item to my project of the FlowDocument type. Let's call it 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>

I put it in a seperate file because I want to avoid putting big blobs of text in the middle of my PrettyInfoWindow.

Now, in my PrettyInfoWindow, I am stumped.

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

I can't find anything on the net about this kind of 'include' functionality, but probably my search-fu is horrible. If this isn't the intended purpose of a FlowDocument.xaml file, then what is?


here is how I would do it :

first, make your CrappyFlowDocument a resource by adding a key to it and putting it in a resource dictionary:

in App.xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="CrappyFlowDocument.xaml" />
    </ResourceDictionary>
</Application.Resources>

in your CrappyFlowDocument.xaml file:

<ResourceDictionary>
    <FlowDocument x:Key="MyCrappyFlowDoc"
                  ColumnWidth="400"
                  FontSize="14"
                  FontFamily="Georgia">
        <Paragraph>
            Woo, my first paragraph!
        </Paragraph>
    </FlowDocument>
</ResourceDictionary>

then, call it directly as the FlowDocumentScrollViewer's "Document" property:

<FlowDocumentScrollViewer Margin="0,0,0,0"
                          Background="#FF414141"
                          Zoom="80"
                          VerticalScrollBarVisibility="Disabled"
                          HorizontalScrollBarVisibility="Disabled"
                          IsSelectionEnabled="False"
                          Document="{StaticResource MyCrappyFlowDoc}" />

I'm not aware of an easier way to do this, hopefully this will suit your needs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜