Annotation Service : FlowDocument « Windows Presentation Foundation « VB.Net






Annotation Service

Annotation Service
      

<Window   
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:a="clr-namespace:System.Windows.Annotations;assembly=PresentationFramework"
    Title="Flow Document Reader + Annotations"
  x:Class="Window1" Initialized="OnInitialized" Closed="OnClosed">
  <StackPanel>
    <StackPanel Orientation="Horizontal">
      <Label>Control Annotations:</Label>
      <Button Command="a:AnnotationService.CreateTextStickyNoteCommand"
         CommandTarget="{Binding ElementName=reader}">Create Text Note</Button>
      <Button Command="a:AnnotationService.CreateInkStickyNoteCommand" CommandTarget="{Binding ElementName=reader}">
        Create Ink Note
      </Button>
      <Button Command="a:AnnotationService.DeleteStickyNotesCommand" CommandTarget="{Binding ElementName=reader}">
        Remove Note
      </Button>
      <Button Command="a:AnnotationService.CreateHighlightCommand"  CommandTarget="{Binding ElementName=reader}">
        Create Yellow Highlight
      </Button>
      <Button Command="a:AnnotationService.ClearHighlightsCommand" CommandTarget="{Binding ElementName=reader}">
        Remove Highlight
      </Button>
    </StackPanel>

    <FlowDocumentReader x:Name="reader">
      <FlowDocument>
        <Paragraph FontSize="22" FontWeight="Bold">Chapter 1</Paragraph>
        <Paragraph FontSize="35" FontWeight="Bold">Why WPF?</Paragraph>
        <Paragraph>
          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>
                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>
          this is another test
        </Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
        <Paragraph>...</Paragraph>
      </FlowDocument>
    </FlowDocumentReader>
  </StackPanel>
</Window>

//File:Window.xaml.vb
Imports System
Imports System.IO
Imports System.Windows
Imports System.Windows.Annotations
Imports System.Windows.Annotations.Storage

Public Partial Class Window1
  Inherits Window
  Private stream As Stream

  Public Sub New()
    InitializeComponent()
  End Sub

  Protected Overloads Sub OnInitialized(sender As Object, e As EventArgs)
    Dim service As AnnotationService = AnnotationService.GetService(reader)
    If service Is Nothing Then
      stream = New FileStream("storage.xml", FileMode.OpenOrCreate)
      service = New AnnotationService(reader)
      Dim store As AnnotationStore = New XmlStreamStore(stream)
      service.Enable(store)
    End If
  End Sub

  Protected Overloads Sub OnClosed(sender As Object, e As EventArgs)
    Dim service As AnnotationService = AnnotationService.GetService(reader)
    If service IsNot Nothing AndAlso service.IsEnabled Then
      service.Store.Flush()
      service.Disable()
      stream.Close()
    End If
  End Sub
End Class

   
    
    
    
    
    
  








Related examples in the same category

1.Add Paragraph to a FlowDocumentAdd Paragraph to a FlowDocument
2.Add Figure into a ParagraphAdd Figure into a Paragraph
3.FlowDocument with a ParagraphFlowDocument with a Paragraph
4.Paragraph elements and FlowDocumentPageViewerParagraph elements and FlowDocumentPageViewer
5.List with ListItems in a FlowDocumentList with ListItems in a FlowDocument
6.Put Paragraph to a ListItemPut Paragraph to a ListItem
7.Table in a FloaterTable in a Floater
8.Set font size for FlowDocumentSet font size for FlowDocument
9.Preserve space in FlowDocumentPreserve space in FlowDocument
10.TableCell and TableRow and TableRowGroupTableCell and TableRow and TableRowGroup
11.Put List to FlowDocumentPut List to FlowDocument
12.Use Table to display tabular data.Use Table to display tabular data.
13.Hyperlink Element
14.Paged ContentPaged Content
15.Text JustificationText Justification
16.Add Bold line to ParagraphAdd Bold line to Paragraph
17.A Paragraph inside a FloaterA Paragraph inside a Floater
18.Add Run of text to a ParagraphAdd Run of text to a Paragraph
19.Set HorizontalAnchor, VerticalAnchor, Background for FigureSet HorizontalAnchor, VerticalAnchor, Background for Figure
20.Nested listsNested lists
21.FontWeight of ParagraphFontWeight of Paragraph
22.BlockUIContainer with a Button along with ParagraphBlockUIContainer with a Button along with Paragraph
23.List MarkerStyleList MarkerStyle
24.Explicit table columnsExplicit table columns
25.Specifying figure widths in columns unitsSpecifying figure widths in columns units
26.Programmatically change the FlowDirection of content within a FlowDocumentReader elementProgrammatically change the FlowDirection of content within a FlowDocumentReader element
27.Use FlowDocumentReader to display FlowDocumentUse FlowDocumentReader to display FlowDocument
28.Programmatically Create and Save a FlowDocumentProgrammatically Create and Save a FlowDocument
29.Use XamlDesignerSerializationManager to write FlowDocumentUse XamlDesignerSerializationManager to write FlowDocument
30.Show FlowDocumentShow FlowDocument
31.Table Flow ContentTable Flow Content
32.Change FlowDocument Width and HeightChange FlowDocument Width and Height
33.Clear FlowDocumentReaderClear FlowDocumentReader
34.Programmatically add rows to a Table element.Programmatically add rows to a Table element.
35.Toggle Hyphenation, Optimal Paragraph, and Column FlexToggle Hyphenation, Optimal Paragraph, and Column Flex
36.Use basic typographic properties.Use basic typographic properties.