FlowDocument with TextAlignment, ColumnWidth. Italic and bold font

image_pdfimage_print


   
      
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  TextAlignment="Justify" 
  IsOptimalParagraphEnabled="True"
  IsHyphenationEnabled="True"
  IsColumnWidthFlexible="True"
  Background="AliceBlue"
  ColumnWidth="300"
  ColumnGap="20">
  <Paragraph>
    <Italic>italic</Italic>
  </Paragraph>
  <Paragraph>
    <Hyperlink NavigateUri="http://www.yourhost.com">website</Hyperlink>
  </Paragraph>
  <Paragraph>
    <Bold>
      bold
    </Bold>
  </Paragraph>
  <Paragraph>
    <Italic>italic</Italic> or <Italic>italic</Italic>.
  </Paragraph>
</FlowDocument>

   
    
    
    
    
    
     


Flow Document Reader

image_pdfimage_print


   
      

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      Title="title">
    <FlowDocumentReader>
        <FlowDocument>
            <Paragraph TextAlignment="Center" FontSize="16pt">
                 Chapter I
            </Paragraph>
            <Paragraph TextAlignment="Center" FontSize="16pt">
                 Paragraph
            </Paragraph>
            <Paragraph TextIndent="24">
                this is a test
            </Paragraph>
            <Paragraph TextIndent="24">
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
                this is a test
            </Paragraph>
            <Paragraph TextIndent="24">
                ...
            </Paragraph>
        </FlowDocument>
    </FlowDocumentReader>
</Page>

   
    
    
    
    
    
     


Add FlowDocument to Button

image_pdfimage_print


   
      

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="FlowDocumentPage" Height="450" Width="500">
    <DockPanel>
        <Button Padding="20" Margin="40">
            <FlowDocumentReader>
                <FlowDocument FontSize="12" xml:space="preserve">
                    <Paragraph TextAlignment="Center" FontSize="18"><Bold>bold</Bold></Paragraph>
                    <Paragraph>Para<Italic>italic</Italic>HTML</Paragraph>
                    <Paragraph>aaa<Button>Push me</Button> 
                    <RadioButton IsChecked="True">Yes</RadioButton>
                    <RadioButton>No</RadioButton>
                    <RadioButton>Unsure</RadioButton>
                    </Paragraph>
                    <Paragraph><Bold>Lists:</Bold></Paragraph>
                    <List>
                        <ListItem><Paragraph>A</Paragraph></ListItem>
                        <ListItem><Paragraph>B</Paragraph></ListItem>
                        <ListItem><Paragraph>C<Ellipse Fill="Red" Width="20" Height="20"/></Paragraph></ListItem>
                        <ListItem><Paragraph>D<Rectangle Fill="Blue" Width="20" Height="20"></Rectangle></Paragraph></ListItem>
                    </List>
                </FlowDocument>
            </FlowDocumentReader>
        </Button>
    </DockPanel>
</Window>

   
    
    
    
    
    
     


FlowDocument with images

image_pdfimage_print


   
      


<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      HorizontalAlignment="Center" VerticalAlignment="Center">

    <FlowDocumentPageViewer>
        <FlowDocument>
          <Paragraph>
            An image in a block container
          </Paragraph>
          <BlockUIContainer>
            <Image Source="c:/Image.jpg" Width="200" />
          </BlockUIContainer>
          <Paragraph>
            An inline UI container:
            <InlineUIContainer BaselineAlignment="Center">
              <Image Source="c:/Image.jpg" Height="40" />
            </InlineUIContainer>
          </Paragraph>
        </FlowDocument>
    </FlowDocumentPageViewer>

</Page>

   
    
    
    
    
    
     


Add Shape(Ellipse, Rectangle) to List

image_pdfimage_print


   
       
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="FlowDocumentPage" Height="450" Width="500">
    <DockPanel>
        <Button Padding="20" Margin="40">
            <FlowDocumentReader>
                <FlowDocument FontSize="12" xml:space="preserve">
                    <Paragraph TextAlignment="Center" FontSize="18"><Bold>bold</Bold></Paragraph>
                    <Paragraph>Para<Italic>italic</Italic>HTML</Paragraph>
                    <Paragraph>aaa<Button>Push me</Button> 
                    <RadioButton IsChecked="True">Yes</RadioButton>
                    <RadioButton>No</RadioButton>
                    <RadioButton>Unsure</RadioButton>
                    </Paragraph>
                    <Paragraph><Bold>Lists:</Bold></Paragraph>
                    <List>
                        <ListItem><Paragraph>A</Paragraph></ListItem>
                        <ListItem><Paragraph>B</Paragraph></ListItem>
                        <ListItem><Paragraph>C<Ellipse Fill="Red" Width="20" Height="20"/></Paragraph></ListItem>
                        <ListItem><Paragraph>D<Rectangle Fill="Blue" Width="20" Height="20"></Rectangle></Paragraph></ListItem>
                    </List>
                </FlowDocument>
            </FlowDocumentReader>
        </Button>
    </DockPanel>
</Window>

   
    
    
    
    
    
    
     


Change FlowDocument Width and Height

image_pdfimage_print


   
  


<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="FlowDocument Optimal Paragraph Sample">
  <StackPanel>
        <CheckBox Click="ToggleHyphenation" Content="Automatic Hyphenation"/>
        <CheckBox Click="ToggleOptimalParagraph" Content="  Enable Optimal Paragraph Layout"/>
        <CheckBox Click="ToggleColumnFlex" Content="Enable Flexible Columns"/>
        <Slider Name="columnWidthSlider" ValueChanged="ChangeColumnWidth"/>
        <Slider Name="columnGapSlider" ValueChanged="ChangeColumnGap"/>
    <FlowDocumentReader Name="flowReader">
      <FlowDocument Name="flowDoc"        TextAlignment="Justify" 
        IsOptimalParagraphEnabled="True"  IsHyphenationEnabled="True"
        IsColumnWidthFlexible="True"      Background="AliceBlue"
        ColumnWidth="300"                 ColumnGap="20">
        <Paragraph><Italic>this is a test</Italic></Paragraph>
        <Paragraph>
          <Hyperlink NavigateUri="http://www-cs-faculty.stanford.edu/~knuth/">
            - Donald E. Knuth
          </Hyperlink>
        </Paragraph>
        <Paragraph><Bold>Principle of Optimal Paragraph</Bold></Paragraph>
        <Paragraph>this is a test <Italic>italic</Italic> </Paragraph>
        <Paragraph>this is a test</Paragraph>
        <Paragraph>this is a test</Paragraph>
        <Paragraph>this is a test</Paragraph>
      </FlowDocument>
    </FlowDocumentReader>
  </StackPanel>
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;


namespace WpfApplication1
{
    public partial class Window1 : Window
    {

        void ToggleHyphenation(Object sender, RoutedEventArgs args)
        {
            flowDoc.IsHyphenationEnabled = ((CheckBox)sender).IsChecked.Value;
        }

        void ToggleOptimalParagraph(Object sender, RoutedEventArgs args)
        {
            flowDoc.IsOptimalParagraphEnabled = ((CheckBox)sender).IsChecked.Value;            
        }

        void ToggleColumnFlex(Object sender, RoutedEventArgs args)
        {
            flowDoc.IsColumnWidthFlexible = ((CheckBox)sender).IsChecked.Value;
        }

        void ChangeColumnWidth(Object sender, RoutedEventArgs args)
        {
                if (columnWidthSlider.Value == 0) 
                {
                    flowDoc.ColumnWidth = 100;
                }
                else if (columnWidthSlider.Value == 1)
                {
                    flowDoc.ColumnWidth = 200;
                }
                else if (columnWidthSlider.Value == 2)
                {
                    flowDoc.ColumnWidth = 300;
                }
                else if (columnWidthSlider.Value == 3)
                { 
                    flowDoc.ColumnWidth = 400; 
                }
                else if (columnWidthSlider.Value == 4)
                { 
                    flowDoc.ColumnWidth = 500; 
                }

        }
        void ChangeColumnGap(Object sender, RoutedEventArgs args)
        {
     
                if (columnGapSlider.Value == 0)
                {
                    flowDoc.ColumnGap = 5;
                }
                else if (columnGapSlider.Value == 1)
                {
                    flowDoc.ColumnGap = 10;
                }
                else if (columnGapSlider.Value == 2)
                {
                    flowDoc.ColumnGap = 15;
                }
                else if (columnGapSlider.Value == 3)
                {
                    flowDoc.ColumnGap = 20;
                }
                else if (columnGapSlider.Value == 4)
                {
                    flowDoc.ColumnGap = 25;
                }

        }
    }
}

   
    
     


Programmatically change the FlowDirection of content within a FlowDocumentReader element

image_pdfimage_print


   
  

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="WpfApplication1.Window1" Title="FlowDirection Sample">

    <DockPanel HorizontalAlignment="Left" VerticalAlignment="Top">
      <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="0,0,0,10">
        <Button Click="LR">LeftToRight</Button>
        <Button Click="RL">RightToLeft</Button>
      </StackPanel>
      <TextBlock Name="txt1" DockPanel.Dock="Bottom" Margin="0,50,0,0"/>
      <FlowDocumentReader>
        <FlowDocument FontFamily="Arial" Name="tf1" >
          <Paragraph>this is a test</Paragraph>
          <Paragraph>this is a test</Paragraph>
      </FlowDocument>
      </FlowDocumentReader>
    </DockPanel>
</Window>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace WpfApplication1
{

  public partial class Window1 : Window
  {
        public void LR(object sender, RoutedEventArgs e)
        {
            tf1.FlowDirection = FlowDirection.LeftToRight;
            txt1.Text = "FlowDirection is now " + tf1.FlowDirection.ToString();
        }
        public void RL(object sender, RoutedEventArgs e)
        {
            tf1.FlowDirection = FlowDirection.RightToLeft;
            txt1.Text = "FlowDirection is now " + tf1.FlowDirection.ToString();
        }
    }
}