Programmatically Create and Save a FlowDocument : FlowDocument « Windows Presentation Foundation « VB.Net Tutorial

VB.Net Tutorial
1.Language Basics
2.Data Type
5.Date Time
6.Class Module
13.Stream File
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
20.Regular Expressions
22.Socket Network
27.Design Patterns
VB.Net Tutorial » Windows Presentation Foundation » FlowDocument 
16.122.28.Programmatically Create and Save a FlowDocument
  Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
    <Button DockPanel.Dock="Bottom" Content="Save..." Click="btnSave_Click"/>
    <FlowDocumentReader x:Name="fdrViewer" />


Imports System
Imports System.IO
Imports System.Windows
Imports System.Windows.Documents
Imports System.Windows.Markup
Imports System.Windows.Media
Imports System.Windows.Shapes
Imports System.Xml
Imports Microsoft.Win32

Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window
    Public Sub New()
    End Sub
    Private Sub btnSave_Click(sender As Object, e As RoutedEventArgs)

      SaveFile("c:\", fdrViewer.Document)
    End Sub
    Private Sub SaveFile(fileName As String, documentSource As IDocumentPaginatorSource)
      Dim xmlWriter As XmlTextWriter = Nothing
      Dim writer As TextWriter = Nothing
      Dim file__1 As Stream = Nothing

        file__1 = File.Create(fileName)
        writer = New StreamWriter(file__1)

        xmlWriter = New XmlTextWriter(writer)

        Dim xamlManager As New XamlDesignerSerializationManager(xmlWriter)

        XamlWriter.Save(documentSource.DocumentPaginator.Source, xamlManager)
      Catch e As Exception
        Dim msg As String = String.Format("Error occurred during saving.{0}{0}{1}", Environment.NewLine, e.Message)

        MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.[Error])
      End Try
    End Sub

    Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
      Dim flowDocument As New FlowDocument()
      Dim paragraph As New Paragraph()
      paragraph.Inlines.Add("This is a paragraph.")


      fdrViewer.Document = flowDocument
    End Sub
  End Class
End Namespace
WPF Programmatically Create And Save A Flow Document
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  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.