O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Control Templates

A Style can set just about any property of an element. The examples in the Style section show rather prosaic properties affecting fonts and such. However, a Style for a ListBox could set the ItemTemplate property to a particular DataTemplate, which has more dramatic effects.

For controls, a Style can also set a very important property named Template. That property points to a control template, which determines the visualization of the control.

“Lookless” Controls

In XAML, the behavior of a control, that is, how it responds to user actions in code, is completely separate from the way the control is rendered. In fact, the code for a control normally doesn't contain any information about how the control is rendered at all. The control's rendering is specified by a control template.

Control authors include a default control template in controls. That way, when the control is placed in a XAML page, a default rendering is in place, and the control can be seen and used.

However, that rendering is just the default. The control template can be changed. The new template can make the control look radically different, using any of the visual elements available in XAML.

Reskinning a CheckBox

Suppose you want a CheckBox to control whether a microphone is turned on or off. You could just drag over a CheckBox and be done with it, and from a functional perspective, that would work. However, usability would be significantly enhanced if you could make the CheckBox indicate its function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required