WPF C# Tutorial

    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">
  
    
      
               CommandTarget="{Binding ElementName=reader}">Create Text Note
      
        Create Ink Note
      
      
        Remove Note
      
      
        Create Yellow Highlight
      
      
        Remove Highlight
      
    

    
      
        Chapter 1
        Why WPF?
        
          this is a test
        

        
                this is a test 
                
        

        
          this is another test
        

        ...
      

    
  

//File:Window.xaml.cs
using System;
using System.IO;
using System.Windows;
using System.Windows.Annotations;
using System.Windows.Annotations.Storage;
public partial class Window1 : Window
{
    Stream stream;
    public Window1()
    {
        InitializeComponent();
    }
    protected void OnInitialized(object sender, EventArgs e)
    {
        AnnotationService service = AnnotationService.GetService(reader);
        if (service == null)
        {
            stream = new FileStream("storage.xml", FileMode.OpenOrCreate);
            service = new AnnotationService(reader);
            AnnotationStore store = new XmlStreamStore(stream);
            service.Enable(store);
        }
    }
    protected void OnClosed(object sender, EventArgs e)
    {
        AnnotationService service = AnnotationService.GetService(reader);
        if (service != null && service.IsEnabled)
        {
            service.Store.Flush();
            service.Disable();
            stream.Close();
        }
    }
}