ToolBar Class

Definition

Provides a container for a group of commands or controls.

[System.Windows.TemplatePart(Name="PART_ToolBarPanel", Type=typeof(System.Windows.Controls.Primitives.ToolBarPanel))]
[System.Windows.TemplatePart(Name="PART_ToolBarOverflowPanel", Type=typeof(System.Windows.Controls.Primitives.ToolBarOverflowPanel))]
public class ToolBar : System.Windows.Controls.HeaderedItemsControl
Inheritance
Attributes

Inherited Members

System.Object

System.Windows.Controls.Control

System.Windows.Controls.HeaderedItemsControl

System.Windows.Controls.ItemsControl

System.Windows.DependencyObject

System.Windows.FrameworkElement

System.Windows.Media.Visual

System.Windows.Threading.DispatcherObject

System.Windows.UIElement

Examples

The following example shows how to create a ToolBar inside a ToolBarTray.

<ToolBarTray Background="White">
  <ToolBar Band="1" BandIndex="1">
    <Button>
      <Image Source="toolbargraphics\new.bmp" />
    </Button>
    <Button>
      <Image Source="toolbargraphics\open.bmp" />
    </Button>
    <Button>
      <Image Source="toolbargraphics\save.bmp" />
    </Button>
    <Separator/>
    <Button>
      <Image Source="toolbargraphics\cut.bmp" />
    </Button>
    <Button>
      <Image Source="toolbargraphics\copy.bmp" />
    </Button>
    <Button>
      <Image Source="toolbargraphics\paste.bmp" />
    </Button>
    <Separator/>
    <Button>
      <Image Source="toolbargraphics\print.bmp" />
    </Button>
    <Button>
      <Image Source="toolbargraphics\preview.bmp" />
    </Button>
  </ToolBar>
</ToolBarTray>

Remarks

ToolBar controls provide an overflow mechanism that places items that do not fit on the ToolBar into an overflow area. Only toolbar elements within a parent ToolBarTray can be moved or resized by the user.

ToolBar is a HeaderedItemsControl, which means its header and collection of objects can be of any type (such as string, image, or panel). For more information, see the HeaderedItemsControl class.

Customizing the ToolBar Control

To apply the same property settings to multiple ToolBar controls, use the Style property. You can modify the default ControlTemplate to give the control a unique appearance. For more information about creating a ControlTemplate, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. To see the parts and states that are specific to the ToolBar, see ToolBar Styles and Templates.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Default WPF Themes.

Note

Setting a visual property will only have an effect if that property is both present in ToolBar control's default template and is set by using a . You can find a list of visual properties in the "Changing the Visual Structure of a Control" section in Customizing the Appearance of an Existing Control by Creating a ControlTemplate.

Constructors

ToolBar()

Initializes a new instance of the ToolBar class.

Fields

BandIndexProperty

Identifies the BandIndex dependency property.

BandProperty

Identifies the Band dependency property.

HasOverflowItemsProperty

Identifies the HasOverflowItems dependency property.

IsOverflowItemProperty

Identifies the System.Windows.Controls.ToolBar.IsOverflowItem attached property.

IsOverflowOpenProperty

Identifies the IsOverflowOpen dependency property.

OrientationProperty

Identifies the Orientation dependency property.

OverflowModeProperty

Identifies the System.Windows.Controls.ToolBar.OverflowMode attached property.

Properties

Band

Gets or sets a value that indicates where the toolbar should be located in the ToolBarTray.

BandIndex

Gets or sets the band index number that indicates the position of the toolbar on the band.

ButtonStyleKey

Gets the Style applied to buttons on a toolbar.

CheckBoxStyleKey

Gets the Style applied to check boxes on a ToolBar.

ComboBoxStyleKey

Gets the Style applied to combo boxes on a ToolBar.

HasOverflowItems

Gets a value that indicates whether the toolbar has items that are not visible.

IsOverflowOpen

Gets or sets a value that indicates whether the ToolBar overflow area is currently visible.

MenuStyleKey

Gets the Style applied to menus on a ToolBar.

Orientation

Gets the orientation of the ToolBar.

RadioButtonStyleKey

Gets the Style applied to radio buttons on a toolbar.

SeparatorStyleKey

Gets the Style applied to separators on a ToolBar.

TextBoxStyleKey

Gets the Style applied to text boxes on a ToolBar.

ToggleButtonStyleKey

Gets the Style applied to ToggleButton controls on a ToolBar.

Methods

GetIsOverflowItem(DependencyObject)

Reads the value of the System.Windows.Controls.ToolBar.IsOverflowItem property from the specified element.

GetOverflowMode(DependencyObject)

Reads the value of the System.Windows.Controls.ToolBar.OverflowMode property from the specified element.

MeasureOverride(Size)

Remeasures a ToolBar.

OnCreateAutomationPeer()

Provides an appropriate ToolBarAutomationPeer implementation for this control, as part of the WPF infrastructure.

OnItemsChanged(NotifyCollectionChangedEventArgs)

Called when the Items property changes.

OnKeyDown(KeyEventArgs)

Provides class handling for the KeyDown routed event that occurs when a key is pressed on an item in the ToolBar.

OnLostMouseCapture(MouseEventArgs)

Provides class handling for the LostMouseCapture routed event that occurs when the ToolBar loses mouse capture.

PrepareContainerForItemOverride(DependencyObject, Object)

Prepares the specified element to display the specified item.

SetOverflowMode(DependencyObject, OverflowMode)

Writes the value of the System.Windows.Controls.ToolBar.OverflowMode property to the specified element.