XAML in a Nutshell - Control Elements
(Page 4 of 4 )
Control elements handle user interaction. Controls are interactive and allow the user to enter data, make choices, and perform other interactive tasks. They can be broken up into five categories: simple controls, content controls, item controls, header item controls, and header content controls. They are differentiated by the attributes they support, namely Content, Headers , and Items . Attribute support is determined by the underlying CLR class represented by the XAML element. Even if you don’t use the Header attribute supported by a header item control, it doesn’t become an item control because the CLR class it represents still has a Header whether or not you assign it a value. Table 3-1 summarizes this information neatly.
Simple controls
Derive directly from the System.Windows.Control class and do not have Content , Items , or Header attributes. Examples of simple controls are HorizontalScrollBar , VerticalScrollBar , Frame , TextBox , and RichTextBox .
Content controls
Have a Content attribute, but no Items or Header attributes. Content controls are restricted to only one element as its content, though that content may be an element (such as a Panel ) that can contain more than one element. Examples of content controls are Button , RepeatButton , Label , RadioButton , CheckBox , ListBoxItem , GroupItem , StatusBarItem , ToolTip , ScrollViewer , and Window .
Item controls
Have an Items attribute, but no Header or Content attributes. Item controls expose a list of elements, usually offering you a choice. Item controls include ListBox , ComboBox , Menu , ContextMenu , RadioButtonList , and TabControl .
Header item controls
Have an Items attribute and a Header attribute but no Content attribute. The Header attribute determines the label for the Items , and the Items attribute contains child elements. The Items attribute is implicitly declared as a sequence of child elements that are not assigned to it. The following declaration of a MenuItem shows how this works:
<MenuItem Header="First Menu Item">
<MenuItem Header="First Child Item" />
<MenuItem Header="Second Child Item" />
</MenuItem>
Header item controls include MenuItem and ToolBar .
Header content controls
Have a Header attribute and a Content attribute, but no Items attribute. Like a content control, the header content control may contain only one child element in its Content attribute. Header content controls include Expander and TabItem .
Table 3-1. Attributes supported by control type
| Content | Header | Items |
|---|
| Simple | N | N | N |
|---|
| Content | Y | N | N |
|---|
| Item | N | N | Y |
|---|
| Header item | N | Y | Y |
|---|
| Header content | Y | Y | N |
|---|
Please check back next week for the continuation of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter 3 of The Basics of XAML, written by Lori A. MacVittie (O'Reilly, 2006; ISBN: 0596526733). Check it out today at your favorite bookstore. Buy this book now.
|
|