Sunday, 20 April 2014

Fixed document and Flow Document in WPF

In this article we are going to see fixed document and flow document in wpf, Let we see what is fixed document and flow document now. In wpf we have a two types of documents which give the rich layout with Pagination, scrolling and Zoom.

Fixed Document :
   In this document we can get the output , what we see in the design, It is like xps print document format.

Normal One: Bind document through code from xps

<DocumentViewer x:Name="docview">           
            <FixedDocument>            
            </FixedDocument>
        </DocumentViewer>


XpsDocument document =                                                                                   new  XpsDocument(@"E:\testing.xps",System.IO.FileAccess.Read);           
docview.Document = document.GetFixedDocumentSequence();


output:



Templated Document Viewer:

<Grid>
        <DocumentViewer x:Name="docview">
            <DocumentViewer.Template>
                <ControlTemplate>
                    <Border>
                        <Border.BorderThickness>
                            <Thickness Bottom="8" Left="8" Right="8" Top="8"></Thickness>
                        </Border.BorderThickness>
                        <Border.Background>
                            <SolidColorBrush x:Name="BorderBrush" Color="Gray"/>
                        </Border.Background>
                        <ScrollViewer CanContentScroll="true"
              HorizontalScrollBarVisibility="Auto"
              x:Name="PART_ContentHost"
              IsTabStop="true"/>
                    </Border>
                </ControlTemplate>
            </DocumentViewer.Template>
            <FixedDocument>
                <PageContent>
                    <FixedPage Width="23.0cm" Height="23.0cm">
                        <TextBlock>Hi Testing</TextBlock>
                    </FixedPage>
                </PageContent>
            </FixedDocument>
        </DocumentViewer>

    </Grid>

output:



Flow Document :
   In this document we can get the output with resize or zoom based on the device and resolution like web pages, Output will differ based on the device.

  <Grid>
        <FlowDocumentReader>
            <FlowDocument>
                <Paragraph>
                    <Bold>Dotnet Concepts</Bold>
                </Paragraph>
                <List>
                    <ListItem>
                        <Paragraph>Oops</Paragraph>
                    </ListItem>
                    <ListItem>
                        <Paragraph>Cryptography</Paragraph>
                    </ListItem>
                    <ListItem>
                        <Paragraph>Com</Paragraph>
                    </ListItem>
                </List>
                <Paragraph>
                    <Bold>Asp.Net</Bold>
                </Paragraph>
                <List>
                    <ListItem>
                        <Paragraph>Life cycle</Paragraph>
                    </ListItem>
                    <ListItem>
                        <Paragraph>Uesr control</Paragraph>
                    </ListItem>
                    <ListItem>
                        <Paragraph>Custom Control</Paragraph>
                    </ListItem>
                </List>
            </FlowDocument>
        </FlowDocumentReader>

    </Grid>

Output:



From this article you can see the fixed and flow document in detail.

No comments:

Post a Comment