Question

There is a pagenumber property in flowdocument reader.But that property is readonly. Is there any way to goto particular page number in flowdocument reader.Please help.

Thanks.

Was it helpful?

Solution

If you are willing to restrict your users to paged display, use FlowDocumentPageViewer instead: this has a GoToPage() method. For some reason GoToPage() doesn't seem to be offered on FlowDocumentReader; I'd guess this is because FlowDocumentReader isn't always in a mode where paging is meaningful (the user can select a continuous scrolling view), and provides its own UI for this when it is meaningful.

You could try sending it the NavigationCommands.GoToPage command, but this is only documented as working on FlowDocumentPageViewer and DocumentViewer; I haven't tested it on FlowDocumentReader.

OTHER TIPS

If you keep track of the Blocks on the FlowDocument contained in the FlowDocumentReader, than you can simply use:

// Getting a block by index
YourReader.Document.Blocks.ElementAt(index).BringIntoView();

// Showing Last Block
YourReader.Document.Blocks.LastBlock.BringIntoView();

// Showing the last Inline
(YourReader.Document.Blocks.LastBlock as Paragraph).Inlines.LastInline.BringIntoView();

This works only on the page ViewingModes of the FlowDocumentReader.

if you whould like to do so on the scroll mode, you must go down the visual tree and search for the ScrollViewer, somthing like this:

        public static ScrollViewer FindScroll(Visual visual)
        {
            if (visual is ScrollViewer)
                return visual as ScrollViewer;

            ScrollViewer searchChiled = null;
            DependencyObject chiled;

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i++)
            {
                chiled = VisualTreeHelper.GetChild(visual, i);
                if (chiled is Visual)
                    searchChiled = FindScroll(chiled as Visual);
                if (searchChiled != null)
                    return searchChiled;
            }

            return null;
        }

ScrollViewer scroller = FindScroll(YourReader as Visual);
if (scroller != null) 
   (scroller as ScrollViewer).ScrollToBottom();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top