Choosing and using interactive controls
Microsoft Expression Blend provides an extensive list of controls that enable you to design a versatile user interface for your Windows Presentation Foundation (WPF) and Microsoft Silverlight applications.
Expression Blend enables you to go above and beyond simply working with default or system controls. Instead, you can actually customize and style controls to your liking to make them perform the way you want. You can also—through the use of resources in Expression Blend—give your custom controls a unique, attractive look, to differentiate your application from others as a way to create a highly branded experience or to create a consistent user interface (UI) across all of your applications. One of the greatest benefits of the control editing model that is present in Expression Blend is that designers can design the appearance of an application at the same time that developers are writing the programming logic. Because a designer can create a design directly, the design won't get lost in translation from mockup to implementation.
What are controls?
Controls (or UI design elements) are the visible components of an application. Controls (such as buttons or lists of selectable items) make it possible for users to interact with your application. If you understand the controls that are available to you in Expression Blend and how to customize them, you can make your application look and behave exactly the way you want.
Expression Blend makes it possible for you to work with controls visually on the artboard, and to configure their appearance and behavior in the Properties panel and the Objects and Timeline panel. For example, you can add a Button control to the artboard, change its appearance by modifying values in the Properties panel, and then start an animation timeline when the button is clicked by adding a behavior from the Assets panel.
For more information, see Properties panel and Objects and Timeline panel.
Beyond those simple actions, you can also do the following things to a control:
Convert a property (such as a brush color) into a resource that you can apply to other controls to create a unique and consistent look for your application.
For an example, see Create a resource.
Create a new template and style for a control that defines its appearance and behavior, also resulting in a unique and consistent look for your application. Templates and styles can include triggers and can use resources to set properties. For more information, see the "Styles and templates" section that follows.
For more information, see the following topics:
Add animations and interactivity to your control.
For an example, see Create a simple animation.
Program more complicated behavior for your control in event handler methods in a code-behind file.
For more information, see Create a new event handler method and Try it: Load a new page dynamically in your Silverlight application.
Design your own custom controls and use them in Expression Blend.
For more information, see the following topics:
Categories of controls
In Expression Blend, you can use many different types of controls to quickly design a visually unique application.
All of the controls are available from the Assets panel by clicking Assets at the bottom of the Tools panel. The Tools panel is along the left side of Expression Blend. When you select a UI element from the Assets panel, the icon for that element appears underneath the Assets button, enabling you to easily select that element again later. The most common UI elements are already displayed underneath the Assets button so that you can locate them quickly.
For more information, see Assets panel and Tools panel.
The following illustration shows the artboard after some of the common UI elements have been added as objects. The Pen tool generates a Path object . The Image icon appeared in the Tools panel after the Image control was selected from the Assets panel.
From the Tools panel to the artboard
A path object named Path_40, representing the shape of the orange color swatch. |
An unnamed button object, representing the button in the application that is labeled "Reset Image". In the Objects and Timeline panel, the underscore (_) is used to identify the access key for the button. |
||
A rectangle object named Rectangle_44, representing one of the paint chips on the color swatch. |
An image object named photo_bathroom, representing the background image of the room. |
||
An unnamed text block identified by the text that it contains, representing the title of the application, "Color Swatch Sample Pack 1". |
To help you decide which control to use, think of the controls in terms of the following categories:
Category |
Use |
Examples |
---|---|---|
Shapes |
Used to create rich visual elements by using ellipses, lines, and rectangles, whose appearance you can make as simple or as complex and colorful as you wish. For more information, see Drawing shapes and paths. You can customize the appearance and behavior of these elements in Expression Blend by using the Properties panel, or by using styles only (not by using templates). For more information, see Edit a style. |
Rectangle Ellipse Path (generated by the Line , Pen , and Pencil drawing tools) |
Layout panels |
Used as a container for other UI elements, to specify their position and window resizing behavior. Unlike most UI elements, some layout panels (such as the Grid) can contain more than one child element. This is useful for organizing and laying out your application design. For more information, see Arranging objects. You can customize the appearance and behavior of these elements in Expression Blend by using the Properties panel, or by using styles (not templates). For more information, see Edit a style. |
Canvas Dock Grid Stack Wrap |
Document/Text |
Used to define document presentation and text formatting. For more information, see Drawing text. You can customize the appearance and behavior of these elements in Expression Blend by using the Properties panel, or by using styles and templates. For more information, see Create or modify a template and Edit a style. |
TextBox TextBlock RichTextBox Label PasswordBox |
Controls |
Used to provide a way for your user to interact with your application. You can customize the appearance and behavior of these elements in Expression Blend by using the Properties panel, or by using styles and templates. For more information, see Create or modify a template and Edit a style. |
Button ListBox Menu RadioButton CheckBox |
Decorators |
Used to apply effects to another element. Decorators can include a single child element, usually the element whose appearance they affect. Typically these elements are used within templates that are applied to other controls, for example, the ButtonChrome element in the template of a button. You can customize the appearance and behavior of the Decorator elements themselves by using the Properties panel, or by using styles only (not by using templates). For more information, see Edit a style. |
Border ButtonChrome Viewbox |
For more information about the characteristics of these control types, see the topic Type Families in the Windows Presentation Foundation section of MSDN.
Creating and modifying controls
You can add a control to the artboard by double-clicking its icon in the Tools panel, or by selecting its icon in the Tools panel and then using your mouse to draw the element on the artboard.
For more information, see the how-to topics listed underneath Choosing and using interactive controls.
Double-clicking a control in the Assets panel inserts the control into the current active element at a default size. This is useful because in many cases the default size will be set to Auto so that the control will size correctly as content is added to it.
After you add a control to the artboard in Expression Blend, it becomes an object in your application. You can modify objects in many ways by using on-object handles to resize, move, rotate, flip, or skew the objects, or by using the Properties panel where you can enter precise values for size, position, and rotation.
For more information, see Add or modify an object, or see the how-to topics that are listed in Working with objects and properties.
Expression Blend is unique in the way in which it allows you to manipulate controls. You can place any other control, panel, or shape element within a control. This is useful in combining controls together. For example, if you want to create a button with an image and text in it, you just drag a StackPanel layout panel onto the button and then add an image and text control into the StackPanel layout panel.
Controls follow certain inheritance rules. For instance, some controls act as a parent element and can have child elements (content) nested within them. Other controls do not support child elements. Expression Blend always attempts to add child elements to the root (or topmost panel) within a document. This means that the LayoutRoot element is considered the root when you first start working in Expression Blend and will, by default, be the destination for all child elements that you insert into the document. If you want to add child elements to a different control within a document, you need to activate that control by double-clicking its name in the Objects and Timeline panel. A yellow highlight identifies the activated element so that you know where a new control will be added.
Expression Blend supports the following different types of controls, which are categorized by the type of inheritance that they support:
Category |
Description |
Examples |
---|---|---|
Simple controls |
Simple controls consist of the controls themselves and the properties that can be set on them. Simple controls do not take content. In other words, they cannot have child elements within them. |
Image ScrollBar |
Content controls |
Content controls can take another element (or can show a string as text for simple scenarios). Content controls have a Content property. This means that they can contain singular content such as a string. Also, content controls can contain another element, such as a layout panel. For an example, see the topic Draw a content control. |
CheckBox RadioButton |
Items controls |
Items controls include a collection of child elements. You can either manually add items to the Items collection property, or you can bind a data collection to the ItemsSource property. Items controls expose items collections and have no Content property and no Header property. For an example, see the topic Draw an items control. |
ComboBox ListBox |
Headered controls |
Headered controls include a header child element that labels the control. Headered controls can either include content (headered content control) or a collection of items (headered items control). For an example, see the topic Draw a headered control. |
TabControl TabItem MenuItem |
For more information about the characteristics of these control types, see the topic "Content Models" in the Windows Presentation Foundation section of MSDN.
Styles and templates
As mentioned previously, you can customize controls in many ways, including by creating templates and styles for controls, resulting in a unique and consistent look for your application. Templates and styles define the pieces that make up a control and the default behavior of the control, respectively. You create templates and styles by making copies of the default system styles and templates for a control (because you can't modify system styles and templates). Modifying templates and styles is an easy way to essentially make new controls in Design view of Expression Blend, without having to use code.
For more information, see the Styling a control that supports templates.