2

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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

4 Comments

I saw the resource dictionary solution elsewhere, but I couldn't get it to work with the flowdocument in its own place when I tried. Would the resource dictionary go into Window.Resources, or was I doing something else wrong?
the best you can do is to put it in your application resources. I edited so that you can see what I mean
I missed your reply (I still wonder why SO stopped giving me notifications while browsing) but thankfully I see it now. I'll give it a shot implementing when I get around to adjusting those flow documents again - for now I settled on hardcoding them in my Windows. :-( So, just out of curiousity... what is the point of the 'New->Flow Document' type Visual Studio offers? It seems useless from all I have seen so far.
there are many uses for this new class, it's a new way of dealing with rich document directly in wpf, without having to deal with a temporary file written in .rtf or whatever other richText format, and then show it in different controls (richtext, flowdocreader etc...). It takes some getting used to though...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.