ScrollToEnd in a flow document

08 Oct 2008

I would like to scroll the flow document completely to its end. Something like doing a Ctrl+End. A simple idea that stuck me was to use BringIntoView() method on a paragraph that is at the end of the flowdocument. To do that, look at the XAML.
<FlowDocumentScrollViewer Name="xD" KeyDown="xD_KeyDown">
        <
FlowDocument>
            <
Paragraph>LONG DOCUMENT IS HERE........................</Paragraph>
            <
Paragraph Name="xx"/>
        </
FlowDocument>
    </
FlowDocumentScrollViewer>

Then in the xd_KeyDown method, simply do the following.
private void xD_KeyDown(object sender, KeyEventArgs e)
{
           if(e.Key==Key.D)
               xx.BringIntoView();
}
So, every time "D" is pressed, the document navigates to the end! simple.