Toggle Hyphenation, Optimal Paragraph, and Column Flex : FlowDocument « Windows Presentation Foundation « VB.Net Tutorial






<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.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Media
Imports System.Windows.Shapes


Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window

    Private Sub ToggleHyphenation(sender As [Object], args As RoutedEventArgs)
      flowDoc.IsHyphenationEnabled = DirectCast(sender, CheckBox).IsChecked.Value
    End Sub

    Private Sub ToggleOptimalParagraph(sender As [Object], args As RoutedEventArgs)
      flowDoc.IsOptimalParagraphEnabled = DirectCast(sender, CheckBox).IsChecked.Value
    End Sub

    Private Sub ToggleColumnFlex(sender As [Object], args As RoutedEventArgs)
      flowDoc.IsColumnWidthFlexible = DirectCast(sender, CheckBox).IsChecked.Value
    End Sub

    Private Sub ChangeColumnWidth(sender As [Object], args As RoutedEventArgs)
      If columnWidthSlider.Value = 0 Then
        flowDoc.ColumnWidth = 100
      ElseIf columnWidthSlider.Value = 1 Then
        flowDoc.ColumnWidth = 200
      ElseIf columnWidthSlider.Value = 2 Then
        flowDoc.ColumnWidth = 300
      ElseIf columnWidthSlider.Value = 3 Then
        flowDoc.ColumnWidth = 400
      ElseIf columnWidthSlider.Value = 4 Then
        flowDoc.ColumnWidth = 500
      End If
    End Sub
    Private Sub ChangeColumnGap(sender As [Object], args As RoutedEventArgs)
      If columnGapSlider.Value = 0 Then
        flowDoc.ColumnGap = 5
      ElseIf columnGapSlider.Value = 1 Then
        flowDoc.ColumnGap = 10
      ElseIf columnGapSlider.Value = 2 Then
        flowDoc.ColumnGap = 15
      ElseIf columnGapSlider.Value = 3 Then
        flowDoc.ColumnGap = 20
      ElseIf columnGapSlider.Value = 4 Then
        flowDoc.ColumnGap = 25
      End If
    End Sub
  End Class
End Namespace
WPF Toggle Hyphenation Optimal Paragraph And Column Flex








16.122.FlowDocument
16.122.1.Add Paragraph to a FlowDocumentAdd Paragraph to a FlowDocument
16.122.2.Add Figure into a ParagraphAdd Figure into a Paragraph
16.122.3.FlowDocument with a ParagraphFlowDocument with a Paragraph
16.122.4.Paragraph elements and FlowDocumentPageViewerParagraph elements and FlowDocumentPageViewer
16.122.5.List with ListItems in a FlowDocumentList with ListItems in a FlowDocument
16.122.6.Put Paragraph to a ListItemPut Paragraph to a ListItem
16.122.7.Table in a FloaterTable in a Floater
16.122.8.Set font size for FlowDocumentSet font size for FlowDocument
16.122.9.Preserve space in FlowDocumentPreserve space in FlowDocument
16.122.10.TableCell and TableRow and TableRowGroupTableCell and TableRow and TableRowGroup
16.122.11.Put List to FlowDocumentPut List to FlowDocument
16.122.12.Use Table to display tabular data.Use Table to display tabular data.
16.122.13.Hyperlink ElementHyperlink Element
16.122.14.Paged ContentPaged Content
16.122.15.Text JustificationText Justification
16.122.16.Add Bold line to ParagraphAdd Bold line to Paragraph
16.122.17.A Paragraph inside a FloaterA Paragraph inside a Floater
16.122.18.Add Run of text to a ParagraphAdd Run of text to a Paragraph
16.122.19.Set HorizontalAnchor, VerticalAnchor, Background for FigureSet HorizontalAnchor, VerticalAnchor, Background for Figure
16.122.20.Nested listsNested lists
16.122.21.FontWeight of ParagraphFontWeight of Paragraph
16.122.22.BlockUIContainer with a Button along with ParagraphBlockUIContainer with a Button along with Paragraph
16.122.23.List MarkerStyleList MarkerStyle
16.122.24.Explicit table columnsExplicit table columns
16.122.25.Specifying figure widths in columns unitsSpecifying figure widths in columns units
16.122.26.Programmatically change the FlowDirection of content within a FlowDocumentReader elementProgrammatically change the FlowDirection of content within a FlowDocumentReader element
16.122.27.Use FlowDocumentReader to display FlowDocumentUse FlowDocumentReader to display FlowDocument
16.122.28.Programmatically Create and Save a FlowDocumentProgrammatically Create and Save a FlowDocument
16.122.29.Use XamlDesignerSerializationManager to write FlowDocumentUse XamlDesignerSerializationManager to write FlowDocument
16.122.30.Show FlowDocumentShow FlowDocument
16.122.31.Table Flow ContentTable Flow Content
16.122.32.Change FlowDocument Width and HeightChange FlowDocument Width and Height
16.122.33.Clear FlowDocumentReaderClear FlowDocumentReader
16.122.34.Programmatically add rows to a Table element.Programmatically add rows to a Table element.
16.122.35.Toggle Hyphenation, Optimal Paragraph, and Column FlexToggle Hyphenation, Optimal Paragraph, and Column Flex
16.122.36.Use basic typographic properties.Use basic typographic properties.
16.122.37.Annotation ServiceAnnotation Service