如何隐藏 WPF DocumentViewer 的菜单栏?

发布于 2024-08-09 00:01:23 字数 311 浏览 6 评论 0原文

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

DocumentViewer 自己的控件剩下的就是顶部的菜单栏(显示缩放设置、打印等)和底部的“查找”栏。我很想删除(或隐藏)这两个栏,但我似乎不知道如何!?

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热鲨 2024-08-16 00:01:23

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

 <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>

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>
海的爱人是光 2024-08-16 00:01:23

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

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

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

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文