Elements and Attributes in XAML
(Page 1 of 4 )
Last week, we began discussing elements in XAML. This week, we continue that discussion and begin looking at attributes. This article, the second of three parts, is excerpted from chapter 3 of
The Basics of XAML, written by Lori A. MacVittie (O'Reilly, 2006; ISBN: 0596526733). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.
Panel Elements
Panel elements handle page layout and act as containers for elements, such as controls or other panels. Some panel-derived elements are used as root elements, but the primary purpose of the panel is to provide support for layout and placement of elements on the page. Some panel classes are intended for designing the user interface, while others are special panels designed specifically for special layout scenarios. An example is the bullet panel, which is used specifically to display only two child elements (usually a text element and a glyph representing a checkbox or a radio button), and is used as a component of other elements such as RadioButton and CheckBox . When you declare a RadioButton , a BulletPanel is one of the underlying components that is rendered on the screen.
The panel elements designed for user-interface design are DockPanel , StackPanel , Canvas , WrapPanel , and Grid .
Shape and Geometric Elements
Shape and geometric elements represent 2-D vector graphics. Shapes derive from the Shape class and represent predefined geometric shapes. WPF shapes available for use with XAML are Ellipse , Line , Path , Polygon , Polyline , and Rectangle . Shapes are a type of UIElement , which means they can be used inside panels and most other controls.
Geometric elements, while also representing 2-D vector graphics, are more flexible than shape elements and can also be used for hit-testing and clipping purposes. Geometry elements can be simple vector graphics such as circles or polygons, or more complex elements comprised of Bezier lines and arcs. Geometries cannot render themselves. They must be drawn by another element, such as Drawing or Path . The attributes common to shape— Fill , Stroke , and StrokeThickness —are attached to the element that draws the geometries rather than the geometry element itself. Geometry elements are CombinedGeometry , LineGeometry , EllipseGeometry , GeometryGroup , PathGeometry , RectangleGeometry , PathSegment , ArcSegment , LineSegment , BezierSegment , QuadraticBezierSegment , PolyQuadraticBezierSegment , PolyLineSegment , PolyBezierSegment , StartSegment , and CloseSegment .
There are some similarities between respective shape and geometric entities. For example, Ellipse and EllipseGeometry provide the same basic functionality, i.e., both declare an ellipse. However, the way in which these elements are interpreted differs. An Ellipse is a standalone element. Its attributes provide all the information necessary to render a complete ellipse. EllipseGeometry , however, does not. Because it is designed to be a part of an ordered collection of geometric types, EllipseGeometry relies on attributes defined on the element appearing before it in the collection. Similarly, attributes assigned to EllipseGeometry will be used to render the next geometry instance in the collection. This trait is shared by all the geometry objects and differentiates them from their Shape -based counterparts.
Next: Document Elements >>
More XML Articles
More By O'Reilly Media
|
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.
|
|