8.1. Base Control Reference This section details the attributes associated with the hierarchy common to controls. It includes the attributes for UIElement, FrameworkElement, and the Control classes (ContentControl, ItemsControl, HeaderedItemsControl, and HeaderedContentControl).
UIElement is the base class for most XAML controls. It provides attributes that determine how elements are displayed. Attributes
AllowDrop This Boolean value determines whether the element can be the target of a drag-and-drop operation.
true The element may be targeted.
false The element may not be targeted. This is the default.
Opacity This Double value describes the opacity factor applied to the element when it is rendered. The range for this value is 0.0-1.0. The default value is 1.0.
OpacityMask This Brush is applied to any alpha-channel masking for the rendered control.
RenderTransform This property specifies a transform (detailed in Chapter 11) to apply to the element.
Visibility This attribute determines the visibility of the control.
Collapsed The element is not displayed and does not occupy layout space.
Hidden The element is not displayed but does occupy layout space.
Visible The element is displayed.
FrameworkElement is the base class for elements in the core presentation set. It also implements many of the virtual methods defined in its parent class, UIElement. Attributes
Focusable This Boolean value determines whether the element is focusable.
true The element is focusable. The default for controls is true.
false The element is not focusable.
Height This attribute determines the height of the control.
Margin This Thickness (detailed in Chapter 7) describes the margin of an element.
Name This attribute sets the name of the object and must be used if codebehind routines will reference the object.
Style This attribute allows a Style (detailed in Chapter 10) to be applied through a StaticResource or DynamicResource or to be described inline.
ToolTip This attribute describes the prompt displayed when the mouse hovers over the element. If the ToolTip is a String, then it can be declared inline; otherwise, it must be declared explicitly.
Width This attribute determines the width of the control. Control | Hierarchy: UIElement FrameworkElement |
Control is the base class for all interactive XAML elements. Attributes
Background This attribute sets the Brush used to paint the control's background. This can be one of the colors from the Color class (see Appendix G). This attribute defaults to TRansparent.
BorderBrush This attribute sets the Brush used to paint the control's border. This attribute defaults to transparent.
BorderThickness This Thickness determines the thickness of the control's border. The default is 0. This attribute is not applicable to RadioButton controls.
FontFamily This String describes the font used in this control. Examples are Arial and Times New Roman.
FontSize This Double value describes the size of the font. The default is the system dialog font size.
FontStyle This attribute describes the style of the font. Options are italic, normal, and oblique.
FontWeight This attribute describes the weight of the font. Options are bold and normal.
Foreground This Brush describes the foreground color.
HorizontalContentAlignment This enumeration determines how the control's content should be aligned horizontally.
Center The content is aligned to the center of the control's layout slot.
Left The content is aligned to the left of the control's layout slot.
Right The content is aligned to the right of the control's layout slot.
Stretch The content is stretched to fill the entirety of the control's layout slot.
Padding This Thickness describes the amount of padding around a control.
TabIndex This Integer determines the order in which a control will receive focus. Lower index controls receive focus before higher index controls. The default value is 1.
TextDecorations This TexTDecorationCollection describes any Textdecoration elements (detailed in Chapter 7) to be added to the control's text. Textdecoration elements specify formatting, such as underlines and overlines, and provide details of the color and placement of such decorations.
TextTrimming This enumeration determines how text will be treated if it runs off the edge of the control.
CharacterEllipsis Text is trimmed at a character boundary. Remaining text is replaced with an ellipsis ( . . . ).
None Text is not trimmed.
WordEllipsis Text is trimmed at a word boundary. Remaining text is replaced with an ellipsis ( . . . ).
VerticalContentAlignment This enumeration determines how the control's content should be aligned vertically.
Bottom The content is aligned at the bottom of the control's layout slot.
Center The content is aligned at the center of the control's layout slot.
Stretch The content is stretched to fill the entirety of the control's layout slot.
Top The content is aligned at the top of the control's layout slot. ContentControl | Hierarchy: UIElement FrameworkElement Control |
ContentControl is the base class for all elements that display a single piece of content, such as ListBoxItem and Label. Attributes
Content Content may be an element of any type. When used to describe the text displayed in or on a control, it is declared inline. When used to hold other types of elements, Content is assumed to comprise those elements declared between the element's beginning and ending tags. <Button Content="This is content" /> is equivalent to declaring <Button>This is content</Button>. Complex attribute types must be declared explicitly between the beginning and end tags of the ContentControl-derived element. Example 8-1 demonstrates the explicit declaration of a non-text element as the single piece of content for a Button. Example 8-1. Explicit declaration of an element within a ContentControl <Button Height="100" Width="100"> <Ellipse CenterX="25" CenterY="25" Fill="Blue" /> </Button> | HeaderedItemsControl | Hierarchy: UIElement FrameworkElement ItemsControl |
HeaderedItemsControl is the base class for all elements that have multiple items as well as a Header. Examples of a HeaderedItemsControl are MenuItem and ToolBar.
Header The Header attribute acts as a label for all HeaderedItemsControl-derived classes, such as MenuItem and ToolBar. HeaderedContentControl | Hierarchy: UIElement FrameworkElement Control ContentControl |
HeaderedContentControl is the base class for all elements that have a single content element and a header. Examples of HeaderedContentControl classes are Expander and TabItem. Attributes
Header The Header attribute acts as a label for all HeaderedContentControl-derived classes, such as Expander and TabItem. ItemsControl | Hierarchy: UIElement FrameworkElement Control |
ItemsControl is the base class for all elements that hold multiple elements. Examples of ItemsControl classes are ComboBox, ListBox, and RadioButtonList. Attributes
Items This implicitly declared attribute is common to all child elements of ItemsControl, which include HeaderedItemsControl, Selector, MenuBase, and StatusBar. |