//<SnippetHandler>
        private void OnAnnotationsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listBox = sender as ListBox;

            if (listBox == null)
            {
                return;
            }

            var comment = listBox.SelectedItem as Annotation;

            if (comment == null)
            {
                return;
            }

            // IAnchorInfo info;
            // service is an AnnotationService object
            // comment is an Annotation object
            _info = AnnotationHelper.GetAnchorInfo(_service, comment);
            var resolvedAnchor = _info.ResolvedAnchor as TextAnchor;

            if (resolvedAnchor != null)
            {
                var textPointer = resolvedAnchor.BoundingStart as TextPointer;
                if (textPointer != null && textPointer.Paragraph != null)
                {
                    textPointer.Paragraph.BringIntoView();
                }
            }
        }
Exemplo n.º 2
0
        private void cmdShowAllAnotations_Click(object sender, RoutedEventArgs e)
        {
            IList <Annotation> annotations = service.Store.GetAnnotations();

            foreach (Annotation annotation in annotations)
            {
                // Check for text information.
                if (annotation.Cargos.Count > 1)
                {
                    // Decode the note text.
                    string base64Text = annotation.Cargos[1].Contents[0].InnerText;
                    byte[] decoded    = Convert.FromBase64String(base64Text);

                    // Write the decoded text to a stream.
                    MemoryStream m = new MemoryStream(decoded);

                    // Get the inner text.
                    //Section section = (Section)XamlReader.Load(m);
                    //TextRange range = new TextRange(section.ContentStart, section.ContentEnd);
                    //string annotationText = range.Text;
                    //m.Position = 0;

                    // Read the full XML.
                    StreamReader r = new StreamReader(m);
                    string       annotationXaml = r.ReadToEnd();
                    r.Close();
                    MessageBox.Show(annotationXaml);

                    // Get the annotated text.
                    IAnchorInfo anchorInfo     = AnnotationHelper.GetAnchorInfo(service, annotation);
                    TextAnchor  resolvedAnchor = anchorInfo.ResolvedAnchor as TextAnchor;
                    if (resolvedAnchor != null)
                    {
                        TextPointer startPointer = (TextPointer)resolvedAnchor.BoundingStart;
                        TextPointer endPointer   = (TextPointer)resolvedAnchor.BoundingEnd;

                        TextRange range = new TextRange(startPointer, endPointer);
                        MessageBox.Show(range.Text);
                    }
                }
            }

            // Code to print annotations.
            //PrintDialog dialog = new PrintDialog();
            //bool? result = dialog.ShowDialog();
            //if (result != null && result.Value)
            //{
            //    System.Windows.Xps.XpsDocumentWriter writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(dialog.PrintQueue);

            //    AnnotationDocumentPaginator adp = new AnnotationDocumentPaginator(
            //                            ((IDocumentPaginatorSource)docReader.Document).DocumentPaginator,
            //                            service.Store);
            //    writer.Write(adp);
            //}
        }
        private void OnShowAllAnotations(object sender, RoutedEventArgs e)
        {
            var annotations = _service.Store.GetAnnotations();

            foreach (var annotation in annotations)
            {
                if (annotation.Cargos.Count > 1)
                {
                    // Decode the note text.
                    var base64Text = annotation.Cargos[1].Contents[0].InnerText;
                    var decoded    = Convert.FromBase64String(base64Text);

                    // Write the decoded text to a stream.
                    string annotationXaml;
                    using (var stream = new MemoryStream(decoded))
                        using (var reader = new StreamReader(stream))
                        {
                            annotationXaml = reader.ReadToEnd();
                        }

                    MessageBox.Show(annotationXaml);

                    // Get the annotated text.
                    var anchorInfo     = AnnotationHelper.GetAnchorInfo(_service, annotation);
                    var resolvedAnchor = anchorInfo.ResolvedAnchor as TextAnchor;
                    if (resolvedAnchor != null)
                    {
                        var startPointer = (TextPointer)resolvedAnchor.BoundingStart;
                        var endPointer   = (TextPointer)resolvedAnchor.BoundingEnd;
                        var range        = new TextRange(startPointer, endPointer);
                        MessageBox.Show(range.Text);
                    }
                }
            }

            #region Code to print annotations

            //PrintDialog dialog = new PrintDialog();
            //bool? result = dialog.ShowDialog();
            //if (result != null && result.Value)
            //{
            //    System.Windows.Xps.XpsDocumentWriter writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(dialog.PrintQueue);

            //    AnnotationDocumentPaginator adp = new AnnotationDocumentPaginator(
            //                            ((IDocumentPaginatorSource)docReader.Document).DocumentPaginator,
            //                            service.Store);
            //    writer.Write(adp);
            //}

            #endregion
        }
Exemplo n.º 4
0
        //<SnippetHandler>
        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();
            }
        }
Exemplo n.º 5
0
        private string GetAnnotationText(Annotation annotation)
        {
            var anchorInfo     = AnnotationHelper.GetAnchorInfo(service, annotation);
            var resolvedAnchor = anchorInfo.ResolvedAnchor as TextAnchor;

            if (resolvedAnchor != null)
            {
                var startPointer = (TextPointer)resolvedAnchor.BoundingStart;
                var endPointer   = (TextPointer)resolvedAnchor.BoundingEnd;
                var range        = new TextRange(startPointer, endPointer);

                return(range.Text);
            }

            return(null);
        }