How to: Change the FlowDirection of Content Programmatically

This example shows how to programmatically change the FlowDirection property of a FlowDocumentReader.

Example

Two Button elements are created, each representing one of the possible values of FlowDirection. When a button is clicked, the associated property value is applied to the contents of a FlowDocumentReader named tf1. The property value is also written to a TextBlock named txt1.

<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>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, 
    sed diam nonummy nibh euismod tincidunt ut laoreet dolore 
    magna aliquam erat volutpat.  Ut wisi enim ad minim veniam, 
    quis nostrud exerci tation ullamcorper suscipit lobortis nisl 
    ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed 
    diam nonummy nibh euismod tincidunt ut laoreet dolore magna 
    aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis 
    nostrud exerci tation ullamcorper suscipit lobortis nisl ut 
    uliquip ex ea commodo consequat. Duis autem vel eum iriure. 
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed 
    diam nonummy nibh euismod tincidunt ut laoreet dolore magna 
    aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis 
    nostrud exerci tation ullamcorper suscipit lobortis nisl ut 
    aliquip ex ea commodo consequat. Duis autem vel eum iriure.
    </Paragraph>
    <Paragraph>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed 
    diam nonummy nibh euismod tincidunt ut laoreet dolore magna 
    aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis 
    nostrud exerci tation ullamcorper suscipit lobortis nisl ut 
    aliquip ex ea commodo consequat. Duis autem vel eum iriure. 
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed 
    diam nonummy nibh euismod tincidunt ut laoreet dolore magna 
    aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis 
    nostrud exerci tation ullamcorper suscipit lobortis nisl ut 
    aliquip ex ea commodo consequat. Duis autem vel eum iriure. 
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed 
    diam nonummy nibh euismod tincidunt ut laoreet dolore magna 
    aliquam erat volutpat.  Ut wisi enim ad minim veniam, quis 
    nostrud exerci tation ullamcorper suscipit lobortis nisl ut 
    aliquip ex ea commodo consequat. Duis autem vel eum iriure.
    </Paragraph>
  </FlowDocument>
</FlowDocumentReader>

The events associated with the button clicks defined above are handled in a C# code-behind file.

        Private Sub LR(ByVal sender As Object, ByVal e As RoutedEventArgs)
            tf1.FlowDirection = FlowDirection.LeftToRight
            txt1.Text = "FlowDirection is now " & tf1.FlowDirection
        End Sub
        Private Sub RL(ByVal sender As Object, ByVal e As RoutedEventArgs)
            tf1.FlowDirection = FlowDirection.RightToLeft
            txt1.Text = "FlowDirection is now " & tf1.FlowDirection
        End Sub
private void LR(object sender, RoutedEventArgs e)
{
    tf1.FlowDirection = FlowDirection.LeftToRight;
    txt1.Text = "FlowDirection is now " + tf1.FlowDirection;
}
private void RL(object sender, RoutedEventArgs e)
{
    tf1.FlowDirection = FlowDirection.RightToLeft;
    txt1.Text = "FlowDirection is now " + tf1.FlowDirection;
}