Understanding the .NET 3.0 Windows Presentation Foundation (WPF) Architecture

This article covers the .NET 3.0's Windows Presentation Foundation (WPF) architecture. It provides information about the major subsystems of WPF and how they interact with them.



The major subsystems of the Windows Presentation Foundation are:

· Object
· Threading.DispatcherObject
· Windows.DependancyObject
· Windows.Media.Visuals
· Windows.UIElements
· Windows.FrameworkElement
· Windows.Controls.Control

Architecture:

The major parts of WPF are:
1. PresentationFramework
2. PresentaionCare
3. Milicore

The details of subsystem are given below:

Object

In WPF Milicore subsystem is designed as unmanaged code, because it has to access the memory of DirectX unmanaged code. Even though CLR provided lot of advantages like memory management, and common exception handling, the performance was considered as main requirement. This approach also allows the Milicore to have fine control over the hardware and software rendering.

The Milicore and managed portion of the presentation subsystem interact with each other using windows messaging.

Threading.DispatcherObject

The Dispatcher system is for handling messages from other object. This dispatcher contains multiple prioritized queues. The DispatcherObject is designed as STA threading model, in which single thread is accessing the object methods and properties. The main reason for this is interoperability with other USER32 components like OLE32 and Clibboard.

The most of the objects in WPF are derived from DispatcherObject, so that each object will have a message queue. The windows messages are also handled using this message queue. These messages includes device input like mouse and keyboard events, framework messages which are part of layout control phase, and commands like menu command etc.

Windows.DependencyObject

The DependencyObject is the system to define the properties of objects. The properties of one object bind to other object property using binding object.

The WPF classws are defined with dozens of properties. The methods and events are used less.

There is a concept property expression, which is the base for property system. In this version this interface is not allowed used outside the framework.

There are other concepts in DependancyObject, like property values with sparse storage, attached properties and events, which are similar to javascript's "expando" feature.

Windows.Media.Visual

Once the system is in place next thing to do is drawing pixels. There are fundamental differences in drawing pictures in user32 and WPF. In user32, windows clip the portion of the component currently getting drawn, so that component can change the pixels with the window rectangle. No pixel on the screen is drawn twice. In WPF every components draw from back to front. This design makes the drawing of transparent windows possible.

WPF displays windows elements by traversing through the unmanaged element's data structures of Milicore. These structures, makes composition nodes, with each node have the rendering instructions. The communication between WPF visual elements and Milicore's composition node happens via windows messaging protocol.
As mentioned earlier, WPF is moving towards the property centric model and these visuals are defined as line object with some properties instead of imperative DrawLine() type model.

Example

<Button>
<StackPanel Orientation="Horizontal">
<Ellipse Fill="Navy" Stroke="Yellow"
Width="30" Height="20" />
<TextBlock VerticalAlignment="Center">
You can put anything in a button!
</TextBlock>
</StackPanel>
</Button>

Windows.UIElement

UIElements defines layout, Input, Event for user interface components.

Components get positioned based on the layout property. There are two phases like Measure and Arrange in layout. The panel asks the child to controls to measure themselves before doing layout.

Events like mouse events are handled by UIElements in two phases, tunnel and bubble. These events traverse through the elements tree in the application UI and any element can handle these events, even like keyboard accelerator events can be handled by any window.

Windows.FrameworkElement

This class provides set of events, properties, and method to WPF core elements to ease the job of WPF user. This class is inherited from the UIElement.
It adds capabilities like Layout system definition, logical tree, lifetime event, support for data binding, dynamic resource reference, animation, and styles to the UIElement.

Windows.Controls.Control

Controls are the basic element for any GUI development. Each control has particular functionality. The controls have properties like foreground, background, padding, etc, which can be customized using template.

The controls separates the data model and interaction model and display model. The separation of data model - properties, interaction model - commands and events, and display model - templates make the customization of a control's look and behavior easier.

The content property of the controls is forming the data model. The WPF controls can contain data of any type, like strings and complex type like person. To display complex types in control data templates can be used.


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.