How can I define three paragraphs under one section ?

We can define three paragraphs under one section as follows. In the following example, the section has a “Background” property value of Red, therefore the background color of the paragraphs is also red. [XAML] <FlowDocument xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’> <!– By default, Section applies no formatting to elements contained within it. However, in this example, the section has a Background property value of ‘Red’, therefore, the three paragraphs (the block) inside the section also have a red background. –> <Section Background=’Red’> <Paragraph> Paragraph 1 </Paragraph> <Paragraph> Paragraph 2 </Paragraph> <Paragraph> Paragraph 3 </Paragraph> </Section> </FlowDocument>

How can I create an application that is used to declare a Context Menu with routed commands that the users can access to create and manage annotations ?

Users typically create annotations by first selecting some text or an item of interest and then right-clicking to display a context menu of annotation options. The following example shows the XAML you can use to declare a Context Menu with routed commands that users can access to create and manage annotations. [XAML] <DocumentViewer.ContextMenu> <ContextMenu> <MenuItem Command=’ApplicationCommands.Copy’ /> <Separator /> <!– Add a Highlight annotation to a user selection. –> <MenuItem Command=’ann:AnnotationService.CreateHighlightCommand’ Header=’Add Highlight’ /> <!– Add a Text Note annotation to a user selection. –> <MenuItem Command=’ann:AnnotationService.CreateTextStickyNoteCommand’ Header=’Add Text Note’ /> <!– Add an Ink Note annotation to a user selection. –> <MenuItem Command=’ann:AnnotationService.CreateInkStickyNoteCommand’ Header=’Add Ink Note’ /> <Separator /> <!– Remove Highlights from a user selection. –> <MenuItem Command=’ann:AnnotationService.ClearHighlightsCommand’ Header=’Remove Highlights’ /> <!– Remove Text Notes and Ink Notes from a user selection. –> <MenuItem Command=’ann:AnnotationService.DeleteStickyNotesCommand’ Header=’Remove Notes’ /> <!– Remove Highlights, Text Notes, Ink Notes from a selection. –> <MenuItem Command=’ann:AnnotationService.DeleteAnnotationsCommand’ Header=’Remove Highlights & Notes’ /> </ContextMenu> </DocumentViewer.ContextMenu>

How can I Match Annotations with Annotated Objects ?

You can match annotations with the corresponding annotated objects. For example, consider a simple document reader application that has a comments pane. The comments pane might be a listbox that displays the text from a list of annotations that are anchored to a document. If the user selects an item in the listbox, then the application brings into view the paragraph in the document that the corresponding annotation object is anchored to. The following piece of C # code demonstrates how to implement the event handler of such a listbox that serves as the comments pane. [C#] void annotationsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { Annotation comment = (sender as ListBox).SelectedItem as Annotation; if (comment != null) { // IAnchorInfo info; // service is an AnnotationService object // comment is an Annotation object info = AnnotationHelper.GetAnchorInfo(this.service, comment); TextAnchor resolvedAnchor = info.ResolvedAnchor as TextAnchor; TextPointer textPointer = (TextPointer)resolvedAnchor.BoundingStart; textPointer.Paragraph.BringIntoView(); } }

How can I do versioning using Custom Serialization ?

Versioning can be done using serialization as follows. [C#] //Version 2.0.0.0 [Serializable] public class MyClass : ISerializable { public int Number; public int NewField; public void GetObjectData( SerializationInfo info,StreamingContext context) { info.AddValue(‘Number’,Number); info.AddValue(‘NewField’,NewField); } protected MyClass(SerializationInfo info,StreamingContext context) { Number = info.GetInt32(‘Number’); Version storedVersion = SerializationUtil.GetVersion(info); if(storedVersion.ToString() == ‘2.0.0.0’) { NewField = info.GetInt32(‘NewField’); } else { NewField = 123;//Some default value } } public MyClass() {} } public static class SerializationUtil { static public Version GetVersion(SerializationInfo info) { string assemblyName = info.AssemblyName; /* AssemblyName is in the form of ‘MyAssembly, Version=1.2.3.4, Culture=neutral,PublicKeyToken=null’ */ char[] separators = {’,’,’=’}; string[] nameParts = assemblyName.Split(separators); return new Version(nameParts[2]); } //Rest of SerializationUtil }

How can I use MemoryStream to create a deep clone of a serializable object ?

This can be done as follows. [C#] public static class SerializationUtil { static public T Clone(T source) { Debug.Assert(typeof(T).IsSerializable); IGenericFormatter formatter = new GenericBinaryFormatter(); Stream stream = new MemoryStream(); formatter.Serialize(stream,source); stream.Seek(0,SeekOrigin.Begin); T clone = formatter.Deserialize(stream); stream.Close(); return clone; } //Rest of SerializationUtil }