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?

Stigma
  • 1,686
  • 13
  • 27

1 Answers1

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

David
  • 6,014
  • 4
  • 39
  • 55
  • 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? – Stigma Dec 15 '10 at 11:34
  • the best you can do is to put it in your application resources. I edited so that you can see what I mean – David Dec 15 '10 at 13:20
  • 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. – Stigma Dec 19 '10 at 09:20
  • 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... – David Dec 20 '10 at 08:13