Most Windows applications offer toolbars as well as menus. Toolbars provide faster access for frequently used operations, because the user does not need to navigate through the menu system—the toolbar is always visible on-screen. Figure 5-28 shows a pair of typical toolbars.

Figure 5-28. Application with toolbars

WPF supports toolbars through the ToolBarTray and ToolBar controls. ToolBarTray provides a container into which you can add multiple ToolBar elements. Example 5-27 shows a simple example with two toolbars; this is the markup for the toolbars in Figure 5-28.

Example 5-27. ToolBarTray and ToolBar

<ToolBarTray> <ToolBar>


<Canvas Width="16" Height="16" SnapsToDevicePixels="True"> <Polygon Stroke="Black" StrokeThickness="0.5"

Points="2.5,1.5 9.5,1.5 12.5,4.5 12.5,15 2.5,15"> <Polygon.Fill>

<LinearGradientBrush StartPoint="1,1" EndPoint="0.2,0.7"> <GradientStop Offset="0" Color="#AAA" /> <GradientStop Offset="1" Color="White" /> </LinearGradientBrush> </Polygon.Fill> </Polygon>

<Polygon Stroke="Black" Fill="DarkGray" StrokeThickness="0.5" StrokeLineJoin="Bevel" Points="9.5,1.5 9.5,4.5 12.5,4.5" />


<Canvas Width="16" Height="16" > <Polygon Stroke="Black" StrokeThickness="0.5" Fill="Khaki" SnapsToDevicePixels="True"

Points="0.5,14.5 0.5,4.5 1.5,3.5 6.5,3.5 8.5,5.5 12.5,5.5 12.5,14.5" /> <Polygon Stroke="Black" SnapsToDevicePixels="True" StrokeThickness="0.5"

Points="1.5,14.5 4.5,7.5 15.5,7.5 12.5,14.5" > <Polygon.Fill>

<LinearGradientBrush StartPoint="0.25,0" EndPoint="0.5,1"> <GradientStop Offset="0" Color="#FF4" /> <GradientStop Offset="1" Color="#CA7" /> </LinearGradientBrush> </Polygon.Fill> </Polygon>

<Path Stroke="Blue" StrokeThickness="1" Data="M 8,2 C 9,1 12,1 14,3" /> <Polygon Fill="Blue" Points="15,1 15.5,4.5 12,4" /> </Canvas> </Button>

</ToolBar> <ToolBar> <Button>Second toolbar</Button> <CheckBox IsChecked="True">Choice</CheckBox> </ToolBar> </ToolBarTray>

This contains just two toolbars, with a couple of buttons each. In this example, we have used some simple vector graphics to draw the usual New and Open icons. The graphical elements used are explained in more detail in Chapter 13. In practice, you would rarely put graphics inline like this—you would usually expect drawings to be resources that are simply referred to by the buttons in the toolbar. See Chapter 12 for more details. The second toolbar just uses the default visuals for a Button and a CheckBox. As you can see, these take on a flat, plain appearance when they appear in a toolbar.

Because toolbar buttons are just normal Button or CheckBox elements with specialized visuals, there is nothing particularly special about their behavior. Toolbars just provide a particular way of arranging and presenting controls. You can also add other elements such as a TextBox or ComboBox. These will just be arranged on the toolbar along with the buttons.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment