简体   繁体   中英

Multipage FlowDocument in WPF

A beginner in WPF Documents here.

I am exploring the possibility to display page by page static content in WPF application. Much like a PowerPoint presentation in which slides can be navigated next and previous.

From my initial research I thought FlowDocument is what I was looking for but I stuck in it while I needed to show multiple pages which can be navigated next and previous.

Anyone can please guide me if I am going the right way using FlowDocument, how I can have multiple pages (or documents)?

Here is what's working as a single page for me:

<FlowDocumentReader  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
        <FlowDocument PagePadding="0" ColumnWidth="999999">
            <Paragraph  Style="{StaticResource headerText}" TextAlignment="Center" >
                <Bold>AGENDA</Bold>
            </Paragraph>
            <List StartIndex="1" MarkerStyle="Decimal" Style="{StaticResource normalText}" MarkerOffset="20" TextAlignment="Left">
                <ListItem>
                    <Paragraph>XAML</Paragraph>
                </ListItem>
                <ListItem>
                    <Paragraph>Layouts in WPF</Paragraph>
                    <List StartIndex="1" Margin="0"  MarkerStyle="Decimal" Style="{StaticResource subText}" MarkerOffset="20" TextAlignment="Left">
                        <ListItem>
                            <Paragraph>Controls</Paragraph>
                        </ListItem>
                        <ListItem>
                            <Paragraph>Styles</Paragraph>
                        </ListItem>
                        <ListItem>
                            <Paragraph>Templates</Paragraph>
                        </ListItem>
                    </List>
                </ListItem>
                <ListItem>
                    <Paragraph>Binding</Paragraph>
                    <List StartIndex="1" Margin="0" MarkerStyle="Decimal" Style="{StaticResource subText}" MarkerOffset="20" TextAlignment="Left">
                        <ListItem>
                            <Paragraph>DependencyObject</Paragraph>
                        </ListItem>
                        <ListItem>
                            <Paragraph>DependencyProperty</Paragraph>
                        </ListItem>
                    </List>
                </ListItem>
            </List>
        </FlowDocument>
    </FlowDocumentReader>

I think the easiest way to do this is just have a content control that binds to a 'CurrentPage' variable within your viewmodel. ie

private UserControl _currentpage
public UserControl CurrentPage { 
    get
    {
        return _currentpage;
    }
    set
    {
       if (PropertyChanged != null)
           PropertyChanged(this, new PropertyChangedEventArgs("CurrentPage"));
    } 
}

public ViewModel()
{
    CurrentPage = new FirstPage();
}

private void NextPageExecuted(object parameter)
{
     //Logic that picks the next page from a set of pages
}

private void PrevPageExecuted(object parameter)
{
     //Logic that picks the previous page from a set of pages
}

then in the xaml just put a generic content control

<ContentControl Content="{Binding CurrentPage}" />

Then just define a user control that defines each page you want to see, FirstPage could be the code you pasted there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM