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

Siyfion picture Siyfion · Oct 30, 2009 · Viewed 12k times · Source

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.

Answer

dtesenair picture dtesenair · Apr 9, 2013

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>