Sunday 20 April 2014

Load the Flow Document from Resource Dictionary Xaml

In this article we are going to see how to load a Flow document from the Resource dictionary, Describe the style for the FlowdocumentPageViewer and define the Flow Document data there in the resource dictionary along with key name, which is used to reference later using that key.


<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   
<FlowDocument x:Key="doctext">
    <Paragraph> <Bold>Mouse Operations</Bold></Paragraph>
    <List>
        <ListItem><Paragraph>Left Click = Menu options</Paragraph></ListItem>
        <ListItem><Paragraph>Right Click = Ok </Paragraph></ListItem>
    </List>
    <Paragraph><Bold>Keyboard Shortcuts</Bold></Paragraph>
    <List>
        <ListItem><Paragraph>Ctrl + a = Select All</Paragraph></ListItem>
            <ListItem><Paragraph>Ctrl + Click = Item selected</Paragraph></ListItem>
        </List>
</FlowDocument>
   
    <Style TargetType="{x:Type FlowDocumentPageViewer}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type FlowDocumentPageViewer}">
                    <AdornerDecorator>
                        <DocumentPageView></DocumentPageView>
                    </AdornerDecorator>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
   

</ResourceDictionary>


Now create a reference in the main window by adding the resource dictionary in the window resources.

<Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Helptext.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Window.Resources>

Code for the main window 

    <Grid>
        <FlowDocumentPageViewer Document="{StaticResource doctext}"></FlowDocumentPageViewer>

    </Grid>

Output:



from this article you can see how to use the resource dictionary in the another window.

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.