Hi,
I'm using a DocumentViewer control to show a fixed document with multiple fixed pages. Individual fixed pages actually contain UI elements (DockPanel, TextBox, TextBlock etc) loaded from different Xaml files using XamlReader. But I cannot select the contents of the textblock shown inside a fixed page. My question is whether it is possible to implement annotations for the static text displayed in TextBlock controls If not what are the other options available for implementing annotations for UI content shown through DocumentViewer
Thanks.

Implementing annotations for FixedDocuments shown in DocumentViewer
Ajornet
Leo TLee
Hi,
I could'nt figure out how to use Figure or Floater in the FixedPage so I used the read-only TextBox in the FixedPage content. Now I'm able to select the content in the read-only TextBox but the annotations are not enabled by the selection. I've given the XAML and code behind below. Same code worked well for FlowDocumentPageViewer.
Can you please tell me what I'm doing wrong here
Thanks
XAML
<
Window x:Class="Annotation_POC.Window2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window2" Height="300" Width="300" WindowState="Maximized" xmlns:annot="clr-namespace:System.Windows.Annotations;assembly=PresentationFramework" Loaded="OnLoaded" Unloaded="OnUnloaded">
<
Grid><
Grid.Resources><
Style x:Key="HighlightColorButtonStyle" TargetType="{x:Type Button}"><
Setter Property="Width" Value="20" /></
Style></
Grid.Resources><
Grid.RowDefinitions><
RowDefinition Height="Auto"/><
RowDefinition/></
Grid.RowDefinitions><
ToolBarTray Grid.Row="0"><!--
Annotations Toolbar --><
ToolBar><!--
StickyNote Operations --><
GroupBox Header="Notes"><
StackPanel Orientation="Horizontal"><
Button Content="Text" Width="30" Command="annot:AnnotationService.CreateTextStickyNoteCommand" Name="btnCreateTextStickyNote" /><
Button Content="Ink" Width="30" Command="annot:AnnotationService.CreateInkStickyNoteCommand" Name="btnCreateInkStickyNote" /><
Button Content="Delete" Width="50" Command="annot:AnnotationService.DeleteStickyNotesCommand" Name="btnDeleteStickyNotes" /></
StackPanel></
GroupBox><!--
Highlight Operations --><
GroupBox Header="Highlight"><
StackPanel Orientation="Horizontal"><
StackPanel Orientation="Horizontal"><
Button Background="Yellow" Style="{StaticResource HighlightColorButtonStyle}" Command="annot:AnnotationService.CreateHighlightCommand" CommandParameter="{x:Static Brushes.Yellow}" /><
Button Background="Green" Style="{StaticResource HighlightColorButtonStyle}" Command="annot:AnnotationService.CreateHighlightCommand" CommandParameter="{x:Static Brushes.Green}" /><
Button Background="Red" Style="{StaticResource HighlightColorButtonStyle}" Command="annot:AnnotationService.CreateHighlightCommand" CommandParameter="{x:Static Brushes.Red}" /><
Button Background="Blue" Style="{StaticResource HighlightColorButtonStyle}" Command="annot:AnnotationService.CreateHighlightCommand" CommandParameter="{x:Static Brushes.Blue}" /><
Button Background="Violet" Style="{StaticResource HighlightColorButtonStyle}" Command="annot:AnnotationService.CreateHighlightCommand" CommandParameter="{x:Static Brushes.Violet}" /></
StackPanel><
Button Content="Clear" Width="50" Command="annot:AnnotationService.ClearHighlightsCommand" /></
StackPanel></
GroupBox></
ToolBar></
ToolBarTray><!--
Viewer and simple content --><
DocumentViewer Name="Viewer" Grid.Row="1"><
FixedDocument><
PageContent><
FixedPage><
TextBox IsReadOnly="True">sample text to test annotations</TextBox></
FixedPage></
PageContent></
FixedDocument></
DocumentViewer></
Grid></
Window>Code behind
using
System;using
System.Windows;using
System.Windows.Controls;using
System.Windows.Data;using
System.Windows.Documents;using
System.Windows.Media;using
System.Windows.Media.Imaging;using
System.Windows.Shapes;using
System.IO;using
System.Windows.Annotations;using
System.Windows.Annotations.Storage;using
System.Windows.Controls.Primitives;namespace
Annotation_POC{
/// <summary> /// Interaction logic for Window2.xaml /// </summary> public partial class Window2 : Window{
public Window2(){
InitializeComponent();
}
// Turn Annotations On. protected void OnLoaded(object sender, RoutedEventArgs e){
// Make sure that an AnnotationService isn’t already enabled. AnnotationService service = AnnotationService.GetService(Viewer); if (service == null){
// (a) Create a Stream for the annotations to be stored in.AnnotationStream =
new FileStream("annotations.xml", FileMode.OpenOrCreate); // (b) Create an AnnotationService on our // FlowDocumentPageViewer.service =
new AnnotationService(Viewer); // (c) Create an AnnotationStore and give it the stream we // created. (Autoflush == false) AnnotationStore store = new XmlStreamStore(AnnotationStream); // (d) "Turn on annotations". Annotations will be persisted in // the stream created at (a).service.Enable(store);
}
}
// Turn Annotations off. protected void OnUnloaded(object sender, RoutedEventArgs e){
// (a) Check that an AnnotationService actually // existed and was Enabled. AnnotationService service = AnnotationService.GetService(Viewer); if (service != null && service.IsEnabled){
// (b) Flush changes to annotations to our stream.service.Store.Flush();
// (c) Turn off annotations.service.Disable();
// (d) Close our stream.AnnotationStream.Close();
}
}
// The stream that we will store annotations in. Stream AnnotationStream;}
}