15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

WPF ❘ ChaPTer 35 cOre wpf<br />

Class<br />

DispatcherObject<br />

Application<br />

DependencyObject<br />

Visual<br />

UIElement<br />

FrameworkElement<br />

Shape<br />

Control<br />

ContentControl<br />

ItemsControl<br />

Panel<br />

desCriPTion<br />

DispatcherObject is an abstract base class for classes that are bound to one<br />

thread. WPF controls require that methods <strong>and</strong> properties be invoked only from<br />

the creator thread. Classes that are derived from DispatcherObject have an<br />

associated Dispatcher object that can be used to switch the thread.<br />

In a WPF application, one instance of the Application class is created. This class<br />

implements a Singleton pattern for access to the application windows, resources,<br />

<strong>and</strong> properties.<br />

DependencyObject is the base class for all classes that support dependency<br />

properties. Dependency properties are discussed in Chapter 27, “Core XAML”.<br />

The base class for all visual elements is Visual. This class includes features for hit<br />

testing <strong>and</strong> transformation.<br />

The abstract base class for all WPF elements needing basic presentation features is<br />

UIElement. This class provides tunneling <strong>and</strong> bubbling events for mouse moves,<br />

drag <strong>and</strong> drop, <strong>and</strong> key clicks. It exposes virtual methods for rendering that can be<br />

overridden by derived classes, <strong>and</strong> it provides methods for layout. WPF does not<br />

use Window h<strong>and</strong>les. You can consider this class equivalent to Window h<strong>and</strong>les.<br />

FrameworkElement is derived from the base class UIElement <strong>and</strong> implements<br />

the default behavior of the methods defined by the base class.<br />

Shape is the base class for all shape elements — for example, Line, Ellipse,<br />

Polygon, <strong>and</strong> Rectangle.<br />

Control derives from FrameworkElement <strong>and</strong> is the base class for all userinteractive<br />

elements.<br />

ContentControl is the base class for all controls that have a single content (for<br />

example, Label, Button). The default style of a content control may be limited,<br />

but it is possible to change the look by using templates.<br />

ItemsControl is the base class for all controls that contain a collection of items<br />

content (for example, ListBox, ComboBox).<br />

The class Panel derives from FrameworkElement <strong>and</strong> is the abstract base<br />

class for all panels. This class has a Children property for all UI elements within<br />

the panel <strong>and</strong> defines methods for arranging the child controls. Classes that are<br />

derived from Panel define different behavior for how the children are organized —<br />

for example, WrapPanel, StackPanel, Canvas, <strong>and</strong> Grid.<br />

As you can see, WPF classes have a really deep hierarchy. In this <strong>and</strong> the next chapters, you see classes of the<br />

core functionality, but it is not possible to cover all the features of WPF in this book.<br />

shaPes<br />

Shapes are the core elements of WPF. With shapes you can draw 2-dimensional graphics using rectangles,<br />

lines, ellipses, paths, polygons, <strong>and</strong> polylines that are represented by classes derived from the abstract base<br />

class Shape. Shapes are defined in the namespace System.Windows.Shapes namespace.<br />

The following XAML example draws a yellow face consisting of an ellipse for the face, two ellipses for the<br />

eyes, two ellipses for the pupils in the eyes, <strong>and</strong> a path for the mouth:<br />

<br />

<br />

<br />

<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!