Search code examples
wpfdocumentviewer

Change WPF DocumentViewer viewing mode


Hello I've got the problem that when I just add a <DocumentViewer x:Name="docViewer" /> I get a toolbar what allow me to change the viewing mode of the XPS document like here: enter image description here

But how can I do this programmatically? I cant find any property that do this and the MSDN and Google say nothing about this feature. Then I found the FlowDocumentReader control what have a ViewingMode property, however it can't display a XPS document. I can't believe that it is not possible to do this, I mean that function is available by default, I just want to change it programmatically...


Solution

  • DocuementViewer didn't exposed any property to change the ViewMode. But in case you want to change the ViewMode programmatically, you can execute the commands exposed by DocumentViewer which are as -

    • DocumentViewer.FitToWidthCommand
    • DocumentViewer.FitToHeightCommand
    • DocumentViewer.FitToMaxPagesAcrossCommand

    You can bind these commands to your custom button or programmatically you can change the ViewMode. Suppose you have a DocuementViewer named documentViewer, you can call these methods on this instance like this -

    • documentViewer.FitToWidth()
    • documentViewer.FitToHeight()
    • documentViewer.FitToMaxPagesAcross()