WPF: How can I remove the searchbox in a DocumentViewer?

documentviewer, wpf

Solution

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;

Problem

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> ``` How can I, in XAML or in C#, eliminate the search box?

Original source

Related problems