Partilhar via


Choosing and using interactive controls

Blend for Visual Studio 2012 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.

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 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 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 Blend and how to customize them, you can make your application look and behave exactly the way you want.

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:

Categories of controls

In 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 JJ170634.0d8b8d29-1af9-418f-8741-be3097d76eab(pt-br,VS.110).png at the bottom of the Tools panel. The Tools panel is along the left side of 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 JJ170634.894f8612-e0ed-4e00-84cf-a9bc8f38fc54(pt-br,VS.110).png generates a Path object JJ170634.e1882d38-c773-4abe-a2b9-10abd293e119(pt-br,VS.110).png. The Image icon JJ170634.adb61060-da5f-4279-8c0d-3681bfeb145c(pt-br,VS.110).png appeared in the Tools panel after the Image control was selected from the Assets panel.

From the Tools panel to the artboard

JJ170634.abd88d9d-ab6c-444e-8037-469cdcb5586a(pt-br,VS.110).png

JJ170634.25182a96-9a69-478a-9cfe-5b360e6a9bea(pt-br,VS.110).png

A path object named Path_40, representing the shape of the orange color swatch.

JJ170634.eb6fad93-f17e-4f62-a926-8c8651862891(pt-br,VS.110).png

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.

JJ170634.05fe4b1d-f584-4bd2-99b6-8bc2d735a89d(pt-br,VS.110).png

A rectangle object named Rectangle_44, representing one of the paint chips on the color swatch.

JJ170634.a5d608f2-bba2-48c5-8b15-2c115db86acc(pt-br,VS.110).png

An image object named photo_bathroom, representing the background image of the room.

JJ170634.f0c1ff71-7814-42ba-806b-7ea92d616e69(pt-br,VS.110).png

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 objects.

You can customize the appearance and behavior of these elements in Blend by using the Properties panel, or by using styles only (not by using templates).

For more information, see Edit a style.

Rectangle JJ170634.ae750268-92e8-403a-9e07-b662da4e9e1e(pt-br,VS.110).png

Ellipse JJ170634.d7a04618-e35a-44f9-b78c-1f22e38016c1(pt-br,VS.110).png

Path (generated by the Line JJ170634.eb618397-5283-48be-8396-3449be7b6fbf(pt-br,VS.110).png, Pen JJ170634.894f8612-e0ed-4e00-84cf-a9bc8f38fc54(pt-br,VS.110).png, and Pencil JJ170634.509dc167-734f-46c9-b012-987ee63450cd(pt-br,VS.110).png 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 Blend by using the Properties panel, or by using styles (not templates).

For more information, see Edit a style.

Canvas JJ170634.95e40288-f7a6-4ddc-9d6a-68d0aa46d621(pt-br,VS.110).png

DockPanel JJ170634.db9f1ff5-6bca-441d-b289-c6781a478a5b(pt-br,VS.110).png

Grid JJ170634.a87ee957-7fbf-4135-a6ab-6de7e63160aa(pt-br,VS.110).png

Stack JJ170634.ec58af86-cc2a-4e1f-91c0-883c5406fdfb(pt-br,VS.110).png

WrapPanel JJ170634.91486eda-6173-4ce8-9610-4f296dcb83d7(pt-br,VS.110).png

Document/Text

Used to define document presentation and text formatting.

For more information, see Format text.

You can customize the appearance and behavior of these elements in 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 JJ170634.343296b4-5c7d-4145-84cc-91b08ba67a1b(pt-br,VS.110).png

TextBlock JJ170634.42165963-00f7-4a33-abcd-b0849edebada(pt-br,VS.110).png

RichTextBox JJ170634.0ee48635-456b-4ebd-b8e4-ce3658417b8e(pt-br,VS.110).png

Label JJ170634.a27042f1-4067-4239-b99a-8b2e4c223de0(pt-br,VS.110).png

PasswordBox JJ170634.31e4dc7e-8cf4-4014-83e4-9b50ec6ee663(pt-br,VS.110).png

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 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 JJ170634.05df1779-a68f-436b-b834-a91b7995a3ec(pt-br,VS.110).png

ListBox JJ170634.ffd7a7c3-6bcd-4ed3-a59e-1f28d06ec4ae(pt-br,VS.110).png

Menu JJ170634.015a263c-0b2b-4253-ac57-b86fcb8c9591(pt-br,VS.110).png

RadioButton JJ170634.33646a24-f5a1-4b74-9496-e0aaddb922c6(pt-br,VS.110).png

CheckBox JJ170634.91bc7bff-27d2-4dfe-93ab-844f2952186f(pt-br,VS.110).png

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 JJ170634.be354518-c54c-4f86-9c57-0b4a9d384b3e(pt-br,VS.110).png

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 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.

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. 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 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.

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 JJ170634.adb61060-da5f-4279-8c0d-3681bfeb145c(pt-br,VS.110).png

ScrollBar JJ170634.6513a026-499e-4296-8a67-7558b466bd33(pt-br,VS.110).png

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 JJ170634.91bc7bff-27d2-4dfe-93ab-844f2952186f(pt-br,VS.110).png

RadioButton JJ170634.33646a24-f5a1-4b74-9496-e0aaddb922c6(pt-br,VS.110).png

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 JJ170634.b174a511-dd12-4a45-a986-034de7693de9(pt-br,VS.110).png

ListBox JJ170634.ffd7a7c3-6bcd-4ed3-a59e-1f28d06ec4ae(pt-br,VS.110).png

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 JJ170634.f13847cd-7fdf-4757-a648-d5ece98fcaea(pt-br,VS.110).png

TabItem

MenuItem JJ170634.82c89430-1209-4aa1-b534-cf1cedac74c7(pt-br,VS.110).png

For more information about the characteristics of these control types, see "WPF Content Model" on 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 Blend, without having to use code.

For more information, see the Styling objects.