你如何隐藏WPF DocumentViewer的菜单栏?

Siy*_*ion 6 wpf xpsdocument documentviewer xps

目前,我DocumentViewer在一个显示XPS文件的WPF窗口中.我创建了自己的"下一页"和"上一页"按钮,并将DocumentViewer.Background属性设置为完全透明.

DocumentViewer自己的控件剩下的就是顶部的菜单栏(显示缩放设置,打印等)和底部的"查找"栏.我很想删除(或隐藏)这两个栏,但我似乎无法弄清楚如何!?

此外,当文档加载时,默认为缩放级别,不会在屏幕上显示整个页面,我需要将其更改为一次显示1页(完全); 我确信有一种方法可以做到这一点但又一次,我还没有找到.

小智 24

这是一种简单的"解决方法"方法,可以隐藏那些不需要覆盖整个控件模板的元素:

 <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>
Run Code Online (Sandbox Code Playgroud)


Nir*_*Nir 8

要删除工具栏,您必须更改DocumentViewer的控件模板.

从此链接http://msdn.microsoft.com/en-us/library/aa970452.aspx中的模板开始, 删除ToolBar元素(也可能是底部的x:Name ="PART_FindToolBarHost"的ContentControl).

关于设置缩放,我没有优雅的XAML解决方案,但您可以在加载文档后调用DocumentViewer的FitToWidth或FitToHeight方法(如果必须,您可以使用每个页面,您已经拥有自己的next/prev页面代码,可以称这些方法)