| |
24.156.31.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.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();
}
}
}
|
|
|
|