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

Controls and Content

Earlier in this chapter, a control was defined as an element that is intended for user input. All XAML elements can respond to mouse and keyboard events, but elements such as the Grid do not, by default, do anything with those events. Controls possess functionality to process events and respond to them in some way.

The base Control class implements a lot of functionality needed by all controls, including:

  • Font properties for sizing and formatting of text
  • Properties for a background, foreground, and border
  • The TabIndex property to control the tab order
  • The capability to use a template to radically alter the appearance of a control

Most developers will have no issues in using these properties, so detailed descriptions are not necessary. This chapter does include a section on Brushes, which is relevant for setting Foreground and Background properties. Also, a section on control templates is included toward the end of the chapter to describe how to alter the fundamental appearance of a control.

Content Controls

Some controls in XAML descend from a base class named ContentControl, and have a property named Content. It is of type Object. You can set the Content property to any .NET object, and XAML will attempt to render it.

The Content property can be set explicitly, or by placing something between the tags of a ContentControl. Both of these are shown in this XAML example:

<Button Content="Save" />
<Button>
    Cancel
</Button>

These two ways of expressing a Button ...

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