How to customize (or remove) the documentviewer toolbar in code (no xml)?

Hi all,
I have a tab control that gets a new tab (with a documentviewer and a button) at runtime as the user selects items from a listbox. There is no xml for the new tabs ( but there is for the tabControl). The new tabs are generated at run time. After some
time I was able to put a couple of rows and have the button in the top row and the documentviewer on the bottom row. Now I'm thinking I want to get rid of the documentviewer toolbar but all examples I can find use xml. I also read that I need to change
the default template for the documentviewer... but again most stuff involves xml. So ... I'm thinking maybe I should modify the toolbar instead to include the button. But I'm not sure which way would be easier.
Comments welcome.
Thanks
private void myListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
if (myListbox.Items.Count > 0)
TabItem newTab = new TabItem();
newTab.Header = myListbox.SelectedValue.ToString();
Button closeButton = new Button();
closeButton.Content = "Close Report";
closeButton.Width = 105;
closeButton.Height = 25;
closeButton.Margin = new Thickness(50, 0, 50, 0);
closeButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
closeButton.VerticalAlignment = System.Windows.VerticalAlignment.Center;
closeButton.AddHandler(Button.ClickEvent, new RoutedEventHandler(closeButton_Click));
DocumentViewer mydoc = new DocumentViewer();
// Need to remove or modify documentViewer toolbar Grid myGrid = new Grid();
RowDefinition topRow = new RowDefinition();
RowDefinition bottomRow = new RowDefinition();
topRow.Height = new GridLength(5, GridUnitType.Star);
bottomRow.Height = new GridLength(95, GridUnitType.Star);
myGrid.RowDefinitions.Insert(myGrid.RowDefinitions.Count, topRow);
myGrid.RowDefinitions.Insert(myGrid.RowDefinitions.Count, bottomRow);
Grid.SetRow(closeButton, 0);
myGrid.Children.Add(closeButton);
Grid.SetRow(mydoc, 1);
myGrid.Children.Add(mydoc);
newTab.Content = myGrid;
mainTabcontrol.Items.Insert(mainTabcontrol.Items.Count, newTab);
private void closeButton_Click(object sender, RoutedEventArgs e)
TabItem tabToClose = new TabItem();
tabToClose = mainTabcontrol.SelectedItem as TabItem;
mainTabcontrol.Items.Remove(tabToClose);

You could add a "dummy" DocumentViewer to your XAML, switch to design mode in Visual Studio 2012 or later, right-click on it and choose Edit Template->Edit a copy to copy the default template into your XAML and then modify it as per your requirements.
You can then remove the "dummy" control, but keep the generated style and assign the Style property of your DocumentViewer to this custom style at runtime:
DocumentViewer mydoc = new DocumentViewer();
mydoc.Style = this.Resources["DocumentViewerStyle1"] as Style;
//or mydoc.Style = Application.Current.Resources["DocumentViewerStyle1"] as Style;
Hiding/removing the Toolbar can be accomplished by setting the Visibility property of the first ContentControl in the default ControlTemplate to Collapsed:
<Window.Resources>
<Style x:Key="DocumentViewerStyle1" BasedOn="{x:Null}" TargetType="{x:Type DocumentViewer}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="ContextMenu" Value="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerContextMenu, TypeInTargetAssembly={x:Type Documents:PresentationUIStyleResources}}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DocumentViewer}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Focusable="False">
<Grid Background="{TemplateBinding Background}" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ContentControl Visibility="Collapsed" Grid.Column="0" Focusable="{TemplateBinding Focusable}" Grid.Row="0" Style="{DynamicResource {ComponentResourceKey ResourceId=PUIDocumentViewerToolBarStyleKey, TypeInTargetAssembly={x:Type Documents:PresentationUIStyleResources}}}" TabIndex="0"/>
<ScrollViewer x:Name="PART_ContentHost" CanContentScroll="true" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalScrollBarVisibility="Auto" IsTabStop="true" Grid.Row="1" TabIndex="1"/>
<DockPanel Grid.Row="1">
<FrameworkElement DockPanel.Dock="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
<Rectangle Height="10" Visibility="Visible" VerticalAlignment="top">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#66000000" Offset="0"/>
<GradientStop Color="Transparent" Offset="1"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</DockPanel>
<ContentControl x:Name="PART_FindToolBarHost" Grid.Column="0" Focusable="{TemplateBinding Focusable}" Grid.Row="2" TabIndex="2"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
If you just want to hide the Toolbar, you could do this programmatically by findind the ContentControl in the visual tree using a helper method like this:
private void myListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
DocumentViewer mydoc = new DocumentViewer();
mydoc.Loaded += (ss, ee) =>
ContentControl cc = FindVisualChildren<ContentControl>(mydoc).FirstOrDefault();
cc.Visibility = System.Windows.Visibility.Collapsed;
private static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
if (depObj != null)
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
yield return (T)child;
foreach (T childOfChild in FindVisualChildren<T>(child))
yield return childOfChild;
If you want to do some more advanced customization, then use the XAML approach and edit the template accordingly.
Hope that helps.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't post several questions in the same thread.

Similar Messages

  • When I play an iMovie at full screen, how can I remove the bottom toolbar

    When I play an iMovie at full screen, how can I remove the bottom toolbar?  It shows up on the projector screen and I don't want my audience to see those tools at the bottom quarter of the screen.

    Do a malware check with a few malware scan programs.
    You need to use all programs because each detects different malware.
    http://www.malwarebytes.org/mbam.php - Malwarebytes' Anti-Malware
    http://www.superantispyware.com/ - SuperAntispyware
    http://www.safer-networking.org/en/index.html - Spybot Search & Destroy
    http://www.lavasoft.com/products/ad_aware_free.php - Ad-Aware Free
    http://www.microsoft.com/windows/products/winfamily/defender/default.mspx - Windows Defender: Home Page
    See also "Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked

  • I have Iphone 4, version 4.3.3 (8J2) How can i remove the brightness toolbar from the main page, below the applications above the shorcuts?

    I have Iphone 4, version 4.3.3 (8J2) How can i remove the brightness toolbar from the main page, below the applications above the shorcuts?

    There is no brightness toolbar unless your iPhone is jailbroken.  If so, you can try to restore to remove the JB.
    The only place brightness exists is under Settings.

  • How do I remove the floating toolbar in a C# program

    Hello,
    I am trying to find out how to remove the floating toolbar in a Winforms C# .NET app. I'm using the
    axAcroPDF control. The toolbar (the floating one) I would like to remove. I have tried the .setShowToolbar() function,
    but this does not work.
    Please help with this as it is very important that this toolbar does not show.
    Thanks
    Mike

    I found a way (sort of) to disable read mode:
    http://blogs.adobe.com/acrolaw/2011/11/turning-off-read-mode-while-viewing-pdfs-in-your-br owser/

  • How can I remove the 'apps' toolbar (the one below the bookmarks toolbar)?

    '''In FF4, how can I remove the 'apps' toolbar?'''
    (My computer screen is now smaller than before due to this new black strip. A 'right click' doesn't help. the "+" on the left only takes me to 'conduit'. I am not interested in this feature at all.)
    Thanks, Reg.

    I had the same problem and was able to remove the empty apps bar by doing the following:
    1. Click on Tools in Mozilla; 2. Click on Add-Ons; 3. Click on Extensions; 4. Look for an add-on called Conduit app; 5. Click to the right of Conduit app to Remove Conduit App; and 6. Restart Firefox: hooray - it's gone!

  • Does anyone know how to remove the Facebook toolbar from Firefox 6.0

    my firefox update,and added facebook,my fault. now my pc crawling,i need to remove the facebook toolbar/addon but it does not show in extensions or plugins, but facebook is there on the pages at the top,so its there,pc ran perfect till face book add on in the update

    Is this a bookmark on the bookmarks toolbar? If so you can remove it by right-clicking on it and selecting Delete.

  • How can I remove the Yahoo toolbar?

    I just upgraded to Firefox 4 and I would like to remove the yahoo toolbar because its just a waist of space any help would be appreciated thanks.

    I found this online and I hope it helps
    There are two ways to remove the Yahoo! Toolbar for Mozilla Firefox.
    The easiest way is to use the "Uninstall" menu item:
    Click the Pencil menu.
    Click "Uninstall".
    Enter any feedback you'd like to send to Yahoo! about why you're uninstalling the toolbar.
    Click "Uninstall".
    Restart your browser.
    If that doesn't work, you can also use the Extension Manager in Firefox to remove the Yahoo! Toolbar extension:
    Click the "Tools" menu in the Firefox browser.
    Click the "Extensions" menu item.
    In the Extensions Manager window scroll until you find the Yahoo! Toolbar extension.
    Click the Yahoo! Toolbar extension.
    Click "Uninstall".
    Click "OK" in the "Uninstall Yahoo! Toolbar" window.
    Exit Extensions Manager and restart your browser.
    Either one of these methods will uninstall Yahoo! Toolbar from your browser. If neither works, your user profile is corrupt. You might need to create a new user profile for your browser.

  • I cannot remove the Yahoo toolbar. it does not appear as an add on

    I have the latest version of Firefox (33.1). I want to remove the yahoo toolbar and disable the yahoo seach function from the address bar (and replace it with google). But when I go to add ons, there is no yahoo in either the plug ins or extebsions. So I cannot delete/remove. What should I do
    Thanks

    It might just be that your search bar (the bar to the right of the address bar) is set to Yahoo, try changing it back to Google. To do that, on the search bar click the icon or the down triangle to display the list of search engines, and select Google from that list.
    If that doesn't fix your problems, did you download Firefox from the official Mozilla site? Sometimes if you search on Google or any search provider, they sometimes have "Advertised links" which are sometimes Firefox bundles that have been slightly modified/shipped with malicious software.
    * https://www.mozilla.org/en-US/firefox/new/
    * https://www.mozilla.org/en-US/firefox/all/
    If you did download from a different website and believe that to be the cause, you can report the link here:
    * https://www.mozilla.org/en-US/about/legal/fraud-report/
    Check your list of install programs in Windows - Control Panel > Programs and Features. Usually malware comes bundled with other applications, so if you sort by date and see several applications installed at the same day, it may be easier to find suspicious applications that way.
    You can try the [https://addons.mozilla.org/en-US/firefox/addon/searchreset/ Search Reset Tool]. It is an extension that will reset your home page, new tab and search settings back to the default then uninstall itself. If you find that its changes are being undone, please see the article [[How to fix preferences that won't save]].
    If none of the above work, and you don't have too many extensions, you can also try the Reset Firefox feature which can fix many issues by restoring Firefox to its factory default state while saving your bookmarks, history, passwords, cookies, and other essential information. '''Note:''' After resetting Firefox, you will lose any extensions, toolbar customizations, and some preferences. See the [[Reset Firefox – easily fix most problems]] article for more information.

  • I would like to be able to remove the 'bookmarks toolbar' from the bookmarks menu.

    Recently Firefox had a .. problem. I'm not sure what it was, or why. I just opened it one day and it had to 'reset'. So, it did, and i lost a bunch of things like addons and themes and stuff like that. Its not a big deal, because all the data was still there. Still, i have to fix some things again.
    I'm still using Firefox 15 - mostly because of some addons that aren't available in later ones, namely an addon that lets me make the window title Aero themed, i like that much more than the solid colours and i can't find one that works with later versions (anyone know of a way around that i would love to hear that too.
    Anyway, my question is simple I used to have the ability (i guess, an addon i've since forgotten about) to go to remove the 'bookmarks toolbar' from the Bookmarks menu. Also, i had a 'save all tabs' or something similar to that. Does anyone know an addon, or tweak, or anything that could get me that again?

    Sounds that you had a chrome folder with a userChrome.css file in it to do such a customization.
    *http://kb.mozillazine.org/userChrome.css
    *http://kb.mozillazine.org/Editing_configuration
    If you have the Old Firefox Data folder on the desktop then check that folder for the chrome folder and copy that folder to the current Firefox Profile Folder.
    You can use this button to go to the Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Show Folder
    See also:
    *[[/questions/877124]]

  • I downloaded a new version of firefox. It said it had problems with my norton toolbar and now it doesn't feature it in the window. I'm not that comp savvy. How do I either get the Norton toolbar up or go back to the old firefox? Thank you.

    I downloaded a new version of firefox. It said it had problems with my norton toolbar and now it doesn't feature it in the window. I'm not that comp savvy. How do I either get the Norton toolbar up or go back to the old firefox? Thank you.

    Please authorize ADE 3 with same credentials that you used with older version of ADE

  • How to escape or remove the special characters in the xml element by regula

    Hi members,
    How to escape or remove the special characters in the xml element by regular expression  in java??
    For Example ,
    <my:name> aaaa </my:name>
    <my:age> 27 </my:age>
    In the above example , i have to retrieve the value of the <my:name> Element(For examlpe -- i have to get "aaaa" from <my:name> tag)...
    How to retreive this value by using DOM with XPATH in java
    Thanks in Advance

    Hi members,
    I forget to paste my coding for the above question....This is my coding......In this display the error...... Pls reply ASAP.......
    PROGRAM:
    import java.io.IOException;
    import java.util.Hashtable;
    import java.util.Map;
    import org.w3c.dom.*;
    import org.xml.sax.SAXException;
    import javax.xml.parsers.*;
    import javax.xml.xpath.*;
    public class DOMReaderForXMP {
         static Document doc;
         static XPath xpath;
         static Object result;
         static NodeList nodes;
         public DOMReaderForXMP() throws ParserConfigurationException, SAXException,
                   IOException, XPathExpressionException {
              DocumentBuilderFactory domFactory = DocumentBuilderFactory
                        .newInstance();
              domFactory.setNamespaceAware(true);
              DocumentBuilder builder = domFactory.newDocumentBuilder();
              doc = builder.parse("d:\\XMP.xml");
              XPathFactory factory = XPathFactory.newInstance();
              xpath = factory.newXPath();
         public static void perform(String path) throws Exception {
              result = xpath.evaluate(path, doc, XPathConstants.NODESET);
              nodes = (NodeList) result;
         public void check() throws Exception {
              perform("//my:name/text()");
              if (!nodes.item(0).getNodeValue().equals("application/pdf")) {
                   System.out.println("Mathces....!");
    ERROR:
    Exception in thread "main" net.sf.saxon.trans.StaticError: XPath syntax error at char 9 in {/my:name}:
    Prefix aas has not been declared

  • How stop PS6 from removing the DPI value from an image when using "save for the web"?

    How stop PS6 from removing the DPI-value from an image when using "save for the web"?
    Example:
    - Open a tif image, that contains a dpi value (resolution).
    - Use the splice tool in PS6.
    - Export the slices with "Save for web", as gif-files.
    Then the dpi value is removed, the gif files has no dpi value (it's empty).
    How can we stop PS6 from removing the dpi value when using "save for web"?
    OR:
    When using the slice tool, how can we save the sliced pieces without PS removing the dpi value?

    you can make your art go a little bit over the bounds. or you can make sure your artboart and art edges align to pixels

  • How to customize to make the MRP controller is optional?

    Now network is assigned to WBS, but the MRP controller is must required.
    how to customize to make the MRP controller is optional?
    Please explain me all the steps to be required.
    Thanks in advance!

    Making MRP controller optional looks non-standard. You can default MRP controller in your network profile (OPUU), so that you need not enter it everytime you create new network.
    Hope this helps.
    Regards

  • How to remove the app-toolbar from projects?

    hi all.
    i know there was somewhere a tutorial-part on how to make the app-toolbar invisible in the layout, but i can't find it anymore.
    i mean the toolbar with
    edit application : edit page X : new : session : debug : show edit-links
    thanks for hint!

    Joshua,
    You only see the toolbar when you are logged into a workspace as a developer. You don't really have to remove it for end users. Try this: make sure you're not logged into a workspace and run your app directly:
    http://<host>:<port/pls/DAD/f?p=<your app ID>:<page ID>
    Sergio

  • How to remove the Ask Toolbar

    The Ask Toolbar has installed itself, it is not listed in the plug ins or extentions. It is not shown on the "Add or remove programs".
    Please can someone tell me how to remove it? It is not as easy as everyone says... I can't get rid of it.

    See this mozillaZine forum thread: http://forums.mozillazine.org/viewtopic.php?f=38&t=627084&p=5069645#p5069645

Maybe you are looking for

  • OTL: Rounding off delays/early departures in OTL

    Could any advice, is it possible to achive below requirement with standard OTL functionality? Delay/Early Departure up to 30 minutes is not considered as delay (delay tolerance is 30 minutes) Delay over 30 minutes is considered delay with the whole a

  • Error 1721 when installing CR XI r2

    Hello - I'm trying to install the above on a server running Windows 2000 Server, and it gets down almost to the end, then throws this error 1721 How do I fix this? Thanks Mark

  • Using Shuffle for classical music

    Am a new IPOD user and am looking for guidance on how to use "shuffle" with classical music .. specifically am looking for a way to have multiple tracks that make up one piece of music be treated as a "song" .. it would appear from what I have seen t

  • New SSM-IPS40 show 50% CPU with no traffic

    We're getting ready to deploy 2 ASA 5585s with SSM-IPS40 modules.  IDM reports 8 cpus at 100% utilization for a total of 50% cpu utilization.  Is IDM reporting this in error?  I'm not finding a way to check on the CLI.  There is no traffic traversing

  • [dwm] key shortcut to shutdown

    Hello guys, I'd like to have a shortcut to shutdown my system via 'sudo shutdown -h now'. How could I extend my config.h to have such a feature on modkey-shift+s? I've already searched the manpages but haven't found any examples how to launch command