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

	<FixedDocument>
		<PageContent>
			<!-- 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"/>
				</StackPanel>
			</FixedPage>
		</PageContent>
		<PageContent>
			<FixedPage Width="672" Height="864">
				<StackPanel Margin="48">
					<TextBlock FontFamily="Cambria" FontSize="14" Width="576" TextWrapping="Wrap">
						There was no possibility etc.
					</TextBlock>
					<TextBlock FontFamily="Cambria" FontSize="14" Width="576" TextWrapping="Wrap" Margin="0,25,0,0">
						I was glad of it etc.
					</TextBlock>
					<Image Margin="0,25,0,0" Source="Twilight.jpg" />
				</StackPanel>
			</FixedPage>
		</PageContent>
	</FixedDocument>

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


And page 2:

Advertisements