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

谁说胖子不能爱 提交于 2019-11-29 00:12:59

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)

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!