tags:

views:

4843

answers:

2

In a nested WPF ToolBarPanel-ToolBar-Menu we want to get rid of the grip handle to the left and the overflow area to the right. they are both grayed out, but we'd like them to not be displayed at all.

any ideas on how to accomplish that?

just in case my terms aren't entirely correct, if you look at the image in Figure 3 of the link below, on the lowest of the three toolbars there's the grip to the left of the dropdown and to the right of the right-most button there's the overflow.

Image of toolbars

+2  A: 

You can use Blend to rather simply override the ControlTemplate for the ToolBarPanel, Menu, or ToolBar.

  1. Right click on the ToolBar and select Edit Template
  2. From Edit Template, select Edit a Copy
  3. I recommend adding the copy to a Resource Dictionary
  4. Click Ok

You'll now be editing the control template for the ToolBarPanel, and can set the visibility to Collapsed for the grip and overflow signal. You can rinse and repeat for the other controls. It is a bit time consuming, but isn't terribly hard with Blend.

sixlettervariables
thanks for the info. unfortunately blend2 and vs2008 don't seem to work well together for us, too many problems when one works with code generated in the other, so we currently don't let blend come anywhere near our vs code ;)
Tom
Yeah we used Blend fairly religiously until VS2k8SP1 came around. Actually I kind of wish the WPF editor in VS2k8 WAS Blend. Much nicer to be able to right click on something and say Group Into 'StackPanel' or 'Border'. Too bad MS wants them to be different experiences.
sixlettervariables
I think the new XAML Power Toys add a feature that allows you to group controls. (Maybe it's the MoXAML Power Toys...)
Number8
+8  A: 

The grip can be removed by setting the attached property ToolBarTray.IsLocked="True" on the ToolBar.

To remove the Overflow ToggleButton, you will have to remove it in a custom ControlTemplate as sixlettervariables suggests, which if you have blend or can download the Blend 3 Preview is not overly difficult.

You could also just hide the button in the loaded event of the ToolBar, though whichever route you take, you should also set the attached property ToolBar.OverflowMode="Never" on the ToolBar's menu, so that items cannot accidentally overflow into an unreachable area.

<ToolBarPanel DockPanel.Dock="Top">
 <ToolBar ToolBarTray.IsLocked="True" Loaded="ToolBar_Loaded">
  <Menu ToolBar.OverflowMode="Never">
   <MenuItem Header="File" />
   <MenuItem Header="New" />
  </Menu>
 </ToolBar>
</ToolBarPanel>

And set the Overflow ToggleButton to collapsed:

private void ToolBar_Loaded(object sender, RoutedEventArgs e)
{
 ToolBar toolBar = sender as ToolBar;
 var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;
 if (overflowGrid != null)
 {
  overflowGrid.Visibility = Visibility.Collapsed;
 }
}
rmoore
Begs the question: Why use a ToolBar at all? Why not just use a simple StackPanel with Buttons? What benefit does the ToolBar provide?
Josh G
In answer to Josh G: If you use a transparent button with an image on a normal panel (StackPanel etc) it will have a white outline. When the same button is placed on a ToolBar though, the white outline is not present.
Chris Bennet