Home Dashboard Directory Help

Document Viewer - ControlTemplate by loewnzaan



Sign in
to vote
Type: Bug
ID: 566538
Opened: 6/10/2010 12:42:50 PM
Access Restriction: Public
User(s) can reproduce this bug


<Style x:Key="{x:Type DocumentViewer}" TargetType="DocumentViewer">
<Setter Property="Foreground"
<Setter Property="Background"
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="ContextMenu"
         Value="{DynamicResource {ComponentResourceKey
         TypeInTargetAssembly={x:Type ui:PresentationUIStyleResources},
<Setter Property="Template">
     <ControlTemplate TargetType="DocumentViewer">
        <Border BorderThickness="{TemplateBinding BorderThickness}"
                BorderBrush="Black" Focusable="False">
         <Grid Background="White"
             <RowDefinition Height="Auto"/>
             <RowDefinition Height="*"/>
             <RowDefinition Height="Auto"/>
             <Button Command="ApplicationCommands.Print"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
             <Button Command="ApplicationCommands.Copy"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
             <Separator />
             <Button Command="NavigationCommands.IncreaseZoom"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Content="Zoom In"/>
             <Button Command="NavigationCommands.DecreaseZoom"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Content="Zoom Out"/>
             <Separator />
             <Button Command="NavigationCommands.Zoom"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Content="Actual Size" />
             <Button Command="DocumentViewer.FitToWidthCommand"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Content="Fit to Width" />
             <Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Content="Whole Page"/>
             <Button Command="DocumentViewer.FitToMaxPagesAcrossCommand"
                CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Content="Two Pages"/>

            <ScrollViewer Grid.Row="1"

            <ContentControl Grid.Row="2"


The following text is translated by machine, sorry, unfortunately, my English is very bad ..
if you beat one of the DocumentViewer ControlTemplate as above (copied from MSDN create). Shown in the window by using it one exception:

"Zoom" is not a valid value for the property "Command".

This error occurs only on Zoom. The program can be started normally, and the Zoom command also works. Only during the design of the error.

Thank You very much!!
Sign in to post a comment.
Posted by Microsoft on 6/13/2012 at 10:32 PM
The WPF team has recently reviewed this issue and will not be addressing this issue as at this time the team is focusing on the bugs impacting the highest number of WPF developers. If you believe that this was resolved in error, please reactivate this bug with any necessary supporting details.
Posted by Andrej Lapajne on 5/18/2012 at 8:12 AM
I love the workaround #2... i.e. to solve the problem, buy another product, and thus even if you'd already spent a few thousands for VS.

Actually, I think MSDN documentation, and particularly the control template sample should be updated with the correct template or at least it should be stated that it is incorrect!!
Posted by Microsoft on 6/10/2010 at 11:14 PM
Thank you for reporting the issue.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.These specialized experts will follow-up with your issue.
Posted by Microsoft on 6/10/2010 at 5:06 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Martin Liversage on 1/17/2012 at 12:10 PM
The DocumentViewer template available on http://msdn.microsoft.com/en-us/library/aa970452.aspx is not the correct template. A tool like Blend will allow you to extract the correct control template and using that template will not exhibit the design time error described here.

This issue should be fixed by updating the documentation on MSDN.
Posted by DD Blue Ox on 9/4/2010 at 9:57 AM
Visual Studio appears to think there is a bug in the way NavigationCommands.Zoom has been implemented, so it won't display the window in the designer. Compiling and running works fine. However, here is how you can work around the issue:

1. Add a new file to your project that will hold a "user command" class. For this example, call it UserCommands.cs. Make it something like this:

using System;
using System.Windows.Input;

namespace UserCommands
    public class ActualSizeCommand
        private static RoutedCommand _actualSize;

        public static RoutedCommand ActualSize
            get { return _actualSize; }

        static ActualSizeCommand()
            _actualSize = new RoutedUICommand("Actual size", "ActualSize", typeof(ActualSizeCommand));

2. In your Window1.xaml file, add the following to the window definition:

3. Within the DocumentViewer definition in the Window1.xaml file, add a command binding:
        <CommandBinding Command="user:ActualSizeCommand.ActualSize" Executed="ActualSize_Executed"/>

4. In the code-behind file for the window, add the ActualSize_Executed handler. In the example below, 'docViewer' is the name given to the DocumentViewer instance as specified in the Window1.xaml file.

private void ActualSize_Executed(object sender, ExecutedRoutedEventArgs e)
    e.Handled = true;
    NavigationCommands.Zoom.Execute(100.0, docViewer);

5. In the control template for the document viewer, replace the button for NavigationCommands.Zoom with the following:

<Button Command="user:ActualSizeCommand.ActualSize"
    ToolTip="Actual Size (Ctrl+0)"
    CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
    Content="Actual Size">

Rebuild, and you will then be able to see the window in the Visual Studio designer.

Dennis Dykstra