Freigeben über


: Enhance Online Reading Experience with WPF

WPF supports two categories of documents: fixed documents and flow documents. Fixed documents look exactly the same whether they're rendered on a screen or a printer. The fixed-format documents supported by WPF are defined by XPS.
Where by the flow documents are intended solely for on-screen display. To make its contents as readable as possible, a flow document can adjust how a document's text and graphics are displayed based on the window size and other factors.
This post will be focusing on flow document.
Flow documents are designed to optimize viewing and readability and are best utilized when ease of reading is the primary document consumption scenario. Rather than being set to one predefined layout, flow documents dynamically adjust and reflow their content based on run-time variables such as window size, device resolution, and optional user preferences.

To display a FlowDocument, WPF includes a few different controls. They are the following:

· FlowDocumentPageViewer: allows moving through a document one page at a time. This control provides a forward and back button along with a zoom control that allows the user to resize the document she's reading.

· FlowDocumentScrollViewer: provides a more traditional scrolling view of a FlowDocument, complete with a scrollbar on the right side of the page.

· FlowDocumentReader: combines the functionality of both FlowDocumentPageViewer and FlowDocumentScrollViewer. It includes features that enable the user to dynamically choose between various viewing modes, including a single-page (page-at-a-time) viewing mode, a two-page-at-a-time (book reading format) viewing mode, and a continuous scrolling (bottomless) viewing mode. If you do not need the ability to dynamically switch between different viewing modes, there are lighter-weight flow content viewers that are fixed in a particular viewing mode.

Below is an example XAML code on using FlowDocumentReader

<Page x:Class="WPF.Document"

    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"

    Title="Document" Height="300" Width="400"

    >

    <Grid>

      <FlowDocumentReader>

        <FlowDocument>

          <Paragraph></Paragraph>

        </FlowDocument>

      </FlowDocumentReader>

    </Grid>

</Page>

Just put the text that you want to display within the <Paragraph></Paragraph>, and you will get something like below screenshot:

There are few built-in controls that comes with the FlowDocumentReader.
At the bottom of the document, there is a slider which allows you to zoom in and zoom out to view the document.

You also will find navigation control, whic allows you to navigate from one page to another page. Besides that, You are also can choose the document viewing mode. You can choose view in single-page, two-page or scrollable page mode.

Simple text search is also one of the built-in control. You can do a simple text search with this control.

Flow content can be complex, consisting of various elements including text, images, tables, and even UIElement derived classes like controls.

<Paragraph> On the Insert tab,<Button Foreground="Maroon">Click Me</Button>the galleries

Refer to this link to learn more on flow document.

Comments

  • Anonymous
    May 05, 2007
    Hi, What is the tool of choice to author a flow document? I've been looking for 2 hours and can't figure this out.  Thank you for any help!! Karl

  • Anonymous
    November 30, 2008
    I wanna show docs in a touch-screen, but the buttons of FlowDocumentReader are too small.