#256 – Use a FixedDocument to Display Content at Fixed Locations

Where FlowDocument allows displaying content that flows automatically from page to page, FixedDocument allows displaying multiple pages of content in a WYSIWYG (What You See Is What You Get) format.  You add content to the document page by page, and specify exactly where each piece of content should be located.

The FixedDocument includes a series of PageContent elements, each of which contains a FixedPage element.

			<!-- 7" x 9" page -->
			<FixedPage Width="672" Height="864">
				<StackPanel Orientation="Vertical" FixedPage.Left="280" FixedPage.Top="150">
					<Label FontFamily="Arial" FontWeight="Bold" FontSize="18" Content="Jane Eyre" HorizontalAlignment="Center"/>
					<Label FontFamily="Arial" FontStyle="Italic" FontSize="14" Content="Charlotte Brontë" HorizontalAlignment="Center"/>
			<FixedPage Width="672" Height="864">
				<StackPanel Margin="48">
					<TextBlock FontFamily="Cambria" FontSize="14" Width="576" TextWrapping="Wrap">
						There was no possibility etc.
					<TextBlock FontFamily="Cambria" FontSize="14" Width="576" TextWrapping="Wrap" Margin="0,25,0,0">
						I was glad of it etc.
					<Image Margin="0,25,0,0" Source="Twilight.jpg" />

The document shows up in a default viewer.  Here’s page 1:

And page 2:


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #256 – Use a FixedDocument to Display Content at Fixed Locations

  1. Christian Swoboda says:

    Can you give me hint, how I can load your example fixeddocument XAML, so that I can finally print it?

    I saved your example as XAML File and tried loading it with the following code:

    FixedDocument document;
    using (FileStream fs = new FileStream(“PrintTemplate.xaml”, FileMode.Open))
    document = (FixedDocument)XamlReader.Load(fs);

    But I can’t compile it because I get the following error:
    “The tag ‘FixedDocument’ does not exist in XML namespace”


    • Sean says:

      This is a XAML fragment that would be part of larger XAML file, e.g. representing a Window in a WPF project. You wouldn’t load the XAML into a FileStream, but render the elements by showing the corresponding WPF window.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: