Customizing SinglePageViewer (Part 1)

posted 2005-10-11

In this post, we'll take a deeper look into SinglePageViewer.

Like other WPF / Avalon Controls, you can modify the ControlTemplate in order to achieve sophisticated customization of your UI. Robbie has various examples where he's customized the look for common UI controls -- we'll be using the same techniques for SinglePageViewer.

Let's start with the minimal ControlTemplate for SinglePageViewer. I won't bother to show the screenshot here, because it's not very interesting -- we've removed all of the UI, if you view this XAML all you'll see is the "Lorem Ipsum" text. Here's the markup:

<SinglePageViewer xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
                  xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">

  <SinglePageViewer.Template>
    <ControlTemplate TargetType="{x:Type SinglePageViewer}">
      <AdornerDecorator>
        <DocumentPageView SinglePageViewer.IsMasterPage="True" />
      </AdornerDecorator>
    </ControlTemplate>
  </SinglePageViewer.Template>

  <FlowDocument>
    <Paragraph>Lorem ipsum</Paragraph>
  </FlowDocument>
</SinglePageViewer>

This isn't as self-explanatory as my previous samples, so I'll go into more detail here. Here's the breakdown tag-by-tag:

Don't worry if you still don't understand 100% of the markup -- you'll typically copy it from an example (or use a tool like Sparkle to create it).

So now you've seen the a minimal ControlTemplate for SinglePageViewer. In the next installment, we'll see how to add an actual interface for this element in order to make it usable.