get current scaling when ScaleMode is FitWidth?

Jan 30, 2012 at 6:49 PM

First off, thanks for making a nice product. I currently have a Silverlight project that displays an XPS doc and was able to get it to successfully display using your control. On initial load I set the control's view mode to fit to the page width. I want to add some basic zooming, but am running into an issue because the Scale property of a ViewMode does not reflect its "true" scale when ScaleMode is set to FitWidth. As an example, my initial ViewMode setting looks like this:

this.MyXpsDocument.ViewMode = new ViewMode()
    ScaleMode = ScaleMode.FitWidth,
    IsDefault = true

Later, when I'm zooming out I'll give it a new ViewMode as follows (slightly simplified for brevity):

ViewMode lastViewMode = this.MyXpsDocument.ViewMode;
this.MyXpsDocument.ViewMode = new ViewMode()
    ScaleMode = ScaleMode.Fixed,
    Scale = lastViewMode.Scale - 0.25,
    IsDefault = lastViewMode.IsDefault

However, this doesn't quite work out because current.Scale is 1.00 even when the ScaleMode was previously set to FitWidth. Therefore it's possible to to zoom out to a scale that appears larger than the fit-to-width scale!

Is there a way to determine the "true" scaling when fit-to-width/fit-to-page, or is there a whole other approach that avoids this issue? I see that there is a ViewModePicker control, but I was having trouble finding information on its usage. Should I be trying to use that? Thanks!

Jan 30, 2012 at 9:08 PM
Edited Jan 30, 2012 at 9:08 PM


The auto scale modes are currently implemented on a per page basis. When two pages in a document have a different size, their scale will differ. This implies that there is no one actual scale for the entire viewer. And that's also the reason there's no API for reading the actual scale of the document viewer, simply because there isn't one. There are N scales, and the actual scale for a page is available on a FixedPageViewer.

With hindsight I should have implemented this per document and not per page, also since your scenario is fairly hard to implement now. 

My advice would be to use a list of fixed and dynamic view modes for the user to pick from. The ViewModePicker is an easy to use control; it comes with a predefined set of viewmodes, you only need to bind the ViewModePicker.SelectedViewMode to the DocumentViewer.ViewMode property like so


<doc:DocumentViewer ViewMode="{Binding SelectedViewMode, ElementName=ViewModePicker}" />
<doc:ViewModePicker x:Name="ViewModePicker" Margin="4,0,0,0" />


- Koen

Jan 31, 2012 at 1:47 PM

Ah, I see. Makes sense.

I switched to using the ViewModePicker and it's working well. Easy to work with too. Thanks again!

Feb 16, 2012 at 10:40 PM
You can just assign the control a whole new IEnumerable of ViewModes in the backend, and that "overrides" the default set. You could probably also modify it to remove specific items.

FYI, if I remember right there's a static method on the ViewMode class called GetDefaultViewModes() that returns the default list. Might not be useful to you but perhaps it will help at some point down the line...


On Thu, Feb 16, 2012 at 2:45 AM, nickvanhooydonk <> wrote:

From: nickvanhooydonk

For the viewmodepicker: Recently I've added a few viewmodes of my own, but I can't find where to disable the predefined set of viewmodes

Read the full discussion online.

To add a post to this discussion, reply to this email (

To start a new discussion for this project, email

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

Feb 20, 2012 at 1:02 AM

I user this for "FitToWidth" and it works perfectly.


Private Sub SetViewFitToWidth()

        Dim newViewMode As New ViewMode()       

newViewMode.ScaleMode = ScaleMode.FitWidth       

newViewMode.IsDefault = Me.Viewer.ViewMode.IsDefault

        Me.Viewer.ViewMode = newViewMode

End Sub