Monday, December 31, 2007

WPF Fundamentals

1. Introduction
Window Presentation Foundation, also named Avalon, is Microsoft's flagship for next generation application UX(user experience) development. It's UI model eliminates the difference of UI elements used in Web page rendering, Windows applications and smart devices. In addition, 3D graphics and animation features are incorporated in this framework so as to create rich user experience for Windows Vista. Also, vector graphics rendering ensures quality for different image size and resolution equipments.


2. XAML
Up front of WPF is XAML - Extensible Application Markup Language, a new markup language standard brought in along with WFP by Microsoft used to describe and define UIs.

Like Asp.net web page, XAML not only has the power for designing layout, it also supports themes and skins to build application-wide consistent pages. Themes and skins are defined as styles.

A XAML document usually refers to two namespaces (see the following code snippet), where XAML schemas are defined. The XAML compiler uses this schema to validate and parse XAML documents.

<Page x:Class="WPFProject.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1">
...
</Page>


3. The WPF Stack
Like most other frameworks, WFP runs on a layered manner. The topmost layer, called Presentation Framework layer, runs on top of Presentation Core layer. These two layers have all the classes of managed code that are controlled by the next layer, the CLR. Under CLR are milcore, User32, and DirectX. They call OS kernel and provide the system support for the top levels

4. WPF Application
The System.Windows.Application class is a framework for defining a WPF application. It exposed programming handlers to customize all aspects accross your application's lifecycle.

... the handlers

System.Windows.Application's StartupUri property is where we can specify the start UI page to run. The following snippet specifies the starting page in XAML tag and with code.

<Application x:Class="WPFProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="whatever.xaml"
>
</Application>

or in behind code:

this.StartupUri = "whatever.xmal";


A WPF application instance can he hosted in a standalone commandline application or in XBAP(XAML Browser Application), a IE embeded application

Visual Studio 2005 provides a choice for a WPF project to be compiled to a console application, Windows applicaiton or a class library.


5. New Programming Features
5.1 Dependency Property
5.2 Attached Property
5.3 Routed Events
5.4 Animation coding

The details of these topics are exmined in another artical.

6. Questions
What is Site of Origin?
How to define and use Resources
A WPF application can be compiled into a class library, in which circumstance and how to access and incorporate the XAML pages?
What is provided by milcore(see 3: The WPF stack)?
How to use databinding in XAML?