本文介绍了WPF:如何在DocumentViewer中删除搜索框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的XAML代码是这样的:
My XAML code is like this:
<Window
xmlns ='http://schemas.microsoft.com/netfx/2007/xaml/presentation'
xmlns:x ='http://schemas.microsoft.com/winfx/2006/xaml'
Title ='Print Preview - More stuff here'
Height ='200'
Width ='300'
WindowStartupLocation ='CenterOwner'>
<DocumentViewer Name='dv1' ... />
</Window>
如何在XAML或C#中消除搜索框?
How can I, in XAML or in C#, eliminate the search box?
推荐答案
使我研究了如何以编程方式获取保存有查找工具栏的ContentControl.我真的不想为DocumentViewer编写一个全新的模板.我只想更改(隐藏)一个控件.这就将问题简化为如何检索通过模板应用的控件?.
这是我发现的:
Vlad's answer led me to look at how to programmatically grab the ContentControl that holds the find toolbar. I didn't really want to write an entirely new template for the DocumentViewer; I wanted to change (hide) only one control. That reduced the problem to how to retrieve a control that is applied via a template?.
Here's what I figured out:
Window window = ... ;
DocumentViewer dv1 = LogicalTreeHelper.FindLogicalNode(window, "dv1") as DocumentViewer;
ContentControl cc = dv1.Template.FindName("PART_FindToolBarHost", dv1) as ContentControl;
cc.Visibility = Visibility.Collapsed;
这篇关于WPF:如何在DocumentViewer中删除搜索框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!