How do you hide a WPF DocumentViewer's menu bars?
Asked Answered
M

2

7

At the moment I have a DocumentViewer in a WPF window that displays an XPS file. I have created my own "Next Page" and "Previous Page" buttons and have set the DocumentViewer.Background property to be completely transparent.

All that is left of the DocumentViewer's own controls is the menu bar at the top (displaying zoom settings, print, etc.) and the "Find" bar at the bottom. I would quite like to remove (or hide) both of these bars, but I can't seem to figure out how!?

Also, when the document is loaded it defaults to a zoom level that doesn't display the entire page on screen, I need to change it to display 1 page at a time (fully); I'm sure there is a way of doing this but again, I haven't found how as yet.

Monk answered 30/10, 2009 at 11:40 Comment(1)
Could you please tell how did you add the custom next page & prev page buttons?Salerno
S
9

To remove the toolbar you have to change the DocumentViewer's control template.

Start with the template in this link http://msdn.microsoft.com/en-us/library/aa970452.aspx and remove the ToolBar element (and maybe also the ContentControl with x:Name="PART_FindToolBarHost" at the bottom).

About setting the zoom, I don't have an elegant XAML solution, but you can call the DocumentViewer's FitToWidth or FitToHeight methods after you load the document (and every page if you must, you already have your own next/prev page code that can call those methods)

Severance answered 2/11, 2009 at 15:1 Comment(0)
M
32

Here's a simple "work-around" way to just hide those elements that doesn't require overriding the entire control template:

 <DocumentViewer>
     <DocumentViewer.Resources>
         <!-- Hides the search box-->
         <Style TargetType="ContentControl">
             <Setter Property="Visibility" Value="Collapsed" />
         </Style>

         <!-- Hides the toolbar -->          
         <Style TargetType="ToolBar">
             <Setter Property="Visibility" Value="Collapsed" />
         </Style>
     </DocumentViewer.Resources>
</DocumentViewer>
Merylmes answered 9/4, 2013 at 19:35 Comment(0)
S
9

To remove the toolbar you have to change the DocumentViewer's control template.

Start with the template in this link http://msdn.microsoft.com/en-us/library/aa970452.aspx and remove the ToolBar element (and maybe also the ContentControl with x:Name="PART_FindToolBarHost" at the bottom).

About setting the zoom, I don't have an elegant XAML solution, but you can call the DocumentViewer's FitToWidth or FitToHeight methods after you load the document (and every page if you must, you already have your own next/prev page code that can call those methods)

Severance answered 2/11, 2009 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.