The Border control draws a border around its single child control. If you want to put more than one control inside the Border, make the child a container such as a Grid and put the other controls inside that.
The control's CornerRadius
property determines the radius of curvature for the Border's corners. Set CornerRadius
to 0 to get square corners.
The BulletDecorator displays an item in a bulleted list. The control's Bullet
property is an object that represents the bullet to display. Next to the bullet, the control displays a single child, normally a Label or TextBlock.
The following XAML code shows how program ControlSamples draws the first item in the bulleted list shown in Figure 2
<Polygon Points="0,5 5,0 10,5 5,10"
Stroke="Black" Fill="Yellow" />
<Label Content="Choice 1"/>
The Button control behaves much like its Windows Forms counterpart. When the user clicks it, the Button raises its Click
The only interesting thing to note here is that the Button can only contain a single child, but you can make that child a container such as a Grid or StackPanel so it's not much of a restriction. The big Button shown in Figure 1
contains a Grid that holds a bunch of other controls.
A Canvas is a container control that lets you explicitly position its child controls by setting their properties. The Canvas provides attached Top
, and Right
properties that determine a child's position. You set the control's Height
, together with either Canvas.Left
For example, the following code shows how program ControlSamples creates the yellow Canvas control and its two Rectangles on the left in Figure 2
<Rectangle Fill="Orange" Stroke="Black"
<Rectangle Fill="Green" Stroke="Black"
The first Rectangle's Canvas.Top
properties position the control 10 pixels down and to the right of the Canvas's upper left corner. The second Rectangle's Canvas.Right
properties position it five pixels left and up from the Canvas's lower right corner.
The CheckBox behaves much as the Windows Forms version does, with as few properties renamed. Instead of Checked
, this version uses IsChecked
to determine whether the box is checked. Similarly, it uses IsThreeState
rather than ThreeState
to determine whether the control allows three states: checked, unchecked, and indeterminate.
Instead of a CheckChanged
event, the control fires separate Checked
events when users check or uncheck it.
Like its Windows Forms counterpart, the ComboBox displays a dropdown list of items that the user can select. The control provides SelectedIndex
, and SelectedValue
properties to let you get or set the current selection.
The ComboBox contains a set of ComboBoxItem controls that hold the choices. Each ComboBoxItem can display a simple text value or hold a child control—possibly a container that holds other controls.
The following code shows how the ControlSamples
program defines its ComboBox. (It's on the left below the CheckBoxes displaying the confused face and the text "Confusion.") The first and last items display simple text while the middle item displays a StackPanel containing an Image and a Label. The second item is selected in Figure 2
so you can see the result.
<ComboBox Margin="5" Width="150" SelectedIndex="1">
<Image Source="Confusion.jpg" Height="30"/>
The ContextMenu displays a popup menu for another control. The control should have a ContextMenu attached element attribute that contains a ContextMenu element, which in turn should contain MenuItems that provide the commands users see in the menu.
The following code builds a Label that contains a ContextMenu.
<Label Content="Right-Click Me"
<MenuItem Name="mnuShowMessage" Header="Show Message"/>
<MenuItem Name="mnuReformat" Header="Reformat Drive"/>
The DockPanel is a container control that can attach its children to its edges. The child controls can use the attached DockPanel.Dock
property to indicate the edge to which they should dock.
The sequence in which you add children to the DockPanel determines their attachment order. Each time it reaches a new child, the DockPanel attaches it to whatever portion of the control is left unclaimed by previous children.
The following code shows how ControlSamples
defines its DockPanel and the Labels it contains. For simplicity, the following code by omits the Labels' BorderBrush
properties that give them the outlines shown in Figure 2
<DockPanel Margin="0,10,0,0" Width="150" Height="100"
<Label Content="Top" DockPanel.Dock="Top"/>
<Label Content="Left" DockPanel.Dock="Left"/>
<Label Content="Bottom" DockPanel.Dock="Bottom"/>
<Label Content="Right" DockPanel.Dock="Right"/>
When the DockPanel's LastChildFill
property is true (which it is by default), the control fills any remaining space with its last child.
|Figure 3. Determined Document: The DocumentViewer displays fixed documents much as Adobe Acrobat displays PDF files.|
The DocumentViewer displays fixed content, much like Adobe Acrobat displays PDF files. The UseDocumentViewer
program shown in Figure 3
contains a DocumentViewer displaying a fixed document. If you resize the window, the DocumentViewer resizes, too, but the document remains unchanged. The text still appears at exactly the positions shown in Figure 3
Unfortunately, the structure of a fixed document is too complex to cover in detail, but briefly, it contains a FixedDocument, which contains one or more PageContent objects. Each of those contains a FixedPage object that contains the document's interesting content: StackPanels, Labels, TextBlocks, and so forth.
Download the UseDocumentViewer
program and look at its XAML code to see how this works.
Note that neither Expression Blend nor Visual Studio understand fixed documents very well, so their designers display error messages instead of content when you work with these controls, although the program still runs. If you need to work with FixedDocuments, use the sample program as a starting point and try to ignore the errors as you build your own programs.