Windows Presentation Foundation – Getting Started

Windows Presentation Foundation is the next generation presentation System for building Rich UI Client applications. WPF contains a Resolution independent and Vector based rendering engine that uses the Modern graphics hardware. The application is developed using Markup and Code behind. The Markup used for the application is eXtensible Application Markup Language (XAML). Similar to ASP.NET or Windows forms we can Instantiate classes, call methods, Get/Set Properties, Raise and Handle Events, etc. WPF combines the Markup Power from ASP.NET with Client Development experience of Windows Forms to give a Unique Programming experience. Usage of XAML eases the Application development by separating the Design from Development.

The following different types of Applications can be developed using WPF:

  1. Standalone WPF Applications – that runs in a Client machine
  2. XAML Browser Applications (XBAP) – that runs in IE

Standalone WPF applications are developed using Window classes, similar to a Form class in Windows forms.

XAML Browser Applications are developed using Page classes, similar to a Page class in ASP.NET

The Designer is a Split window between UI and XAML code. XAML is the XML Markup Language used to define the UI.  XAML files have the extension .xaml.

By default, a Grid container is displayed, in a Window class.

Changing the XAML updates the UI on the fly.The following markup will create a Button.

WPF was built with a principle to give preference to Properties over Methods or Events. Properties specified the Purpose instead of action. Properties became declarative through XAML and were Model driven. Hence more Properties were created to control the System’s behavior.  A rich Property System was developed with the Change Notification feature. The interface INotifyPropertyChange helps an object to publish Change Notifications. Two way Binding was made possible by enabling Change Notification in both sides of Binding. Dependency Properties are the Properties of type “Dependency Object”, which track the Dependencies in the Property expressions and validates the Property whenever the Dependency changes.

WPF has the Principle of Composition, (an element can contain or can be composed of other elements) and component reuse. The properties of an element can depend on the objects contained in it. To help this scenario, Attached Properties are developed, whereby an object can provide Property definitions of other objects.

The following XAML will create a 2*2 Grid and place a Button in first Row first column. Notice the use of Properties in XAML declaration.

Grid.Row and Grid.Column are attached properties because they are the Properties of the grid but are defined by the children of Grid.  We will observe the use of Dependency Properties while discussing Data Binding.

UIElement is the basic system which defines the Layout, Input and Events. The Layout is defined as a contract in two phases, a Measure phase which allows a Component to find out how much space it has and a Arrange phase which allows a Parent element to position and set the sixe for the children.

Framework element derives from UIElement by building on its basic contract. It provides a few Properties like HorizontalAlignment, VerticalAlignment, Margin, etc to help its derivatives follow a unique layout. Control is the basic component that builds up the UI.

Freezables are special objects with two states – Unfrozen and Frozen. In Unfrozen state, Freezables behave as other objects. In Frozen state, cannot be modified. Freezables  improve performance. Brushes, Pens, Transformations, Geometries, Animations are Freezables. They provide Changed Event to notify observers when the object is modified. Freezables improve performance in Frozen state because they don’t spend resources on Change Notifications.

The different elements in the UI exists as an Element tree in a logical order.

Event Handling in WPF is enhanced by the use of Routed Events. A Routed Event is a type of event that can invoke handlers on Multiple listeners in an element tree, rather than just the single object that raised the event. Routed Events have different strategies like

Bubbling – the event travels from the Source element and bubbles upward through the Element Tree until it reaches the root of the element, like a Page or a window.

Tunneling – the event handlers at the root of the Element tree are invoked and the event traverses through successive child elements towards the Element Source that raised the event.

In this post, we have seen the basics of WPF. In future posts, we will dive into each area in WPF. Below are some references that speak about the Basics of WPF.

References

MSDN Articles

  1. An Introduction to Windows Presentation Foundation
  2. Introducing Windows Presentation Foundation
  3. Introducing the March 2005 CTP: What’s New in “Avalon”
  4. Introducing the December 2005 CTP: What’s New in Windows Presentation Foundation
  5. A Guided Tour of Windows Presentation Foundation
  6. Architectural Overview of the Windows Presentation Foundation Beta 1 Release
  7. Create Real apps using New Code and Markup models
  8. 10 Top UI development breakthroughs in WPF
  9. Building Greater User Ex using WPF

MSDN Documentation

  1. WPF Fundamentals
  2. Getting Started
  3. Application Development

How do I videos

  1. How to Create a WPF Application (10:19)
  2. How to Layout a WPF Application (14:05)
  3. How to Use XAML in WPF (10:34)
  4. Build a Standard WPF Application (8 minutes, 25 seconds)

Presentations

  1. MIX 2006
    1. Designer’s overview of WPF
    2. Oppotunity of WPF Applications in Browser and Beyond
    3. Building Real world WPF Application – North Face In Store Explorer
    4. Developing a WPF Application
  2. MIX 2007
    1. Lessons Learnt – Designer/ Developer Productivity in WPF
    2. I see Dead People with WPF
    3. WPF and Olympics 2008 Games
    4. WPF for Developers – 1
    5. WPF for Developers – 2
    6. WPF in Real world Development
  3. MIX 2008
    1. Bring Data to Life using WPF
  4. PDC 2008
    1. Declarative Programming using XAML

Webcasts

  1. WPF Soup to Nuts (Part 01 of 18): Introduction (Level 100)
  2. WPF Soup to Nuts (Part 02 of 18): What Is the Extensible Application Markup Language? (Level 200)
  3. WPF Soup to Nuts (Part 03 of 18): Conceptualizing WPF (Level 200)
  4. WPF Soup to Nuts (Part 04 of 18): Hello World (Level 200)
  5. Building Web Browser Applications with Windows Presentation Foundation (Level 200)
  6. WPF: Introduction (Level 200)
  7. geekSpeak: WPF with Bil Simser (Level 200)
  8. WPF Application Model (Level 200)
  9. Building WPF-Based Applications (Level 200)
  10. What’s New in WPF (Level 100)
  11. WPF Properties, Events, and Commands (Level 200)
  12. Creating Electronic Greeting Cards with WPF and XAML Browser Application Technologies (Level 200)
  13. BenkoTIPS Live and On Demand: WPF Demystified (Level 200)

Virtual Labs

  1. Visual Studio 2008 – Developing a WPF Application
  2. Building WPF Applications VB Part 1
  3. Building WPF Applications VB Part 2
  4. Creating a Simple Application with Procedural Code in WPF and Windows Vista
  5. Building WPF Applications C# Part 1 Virtual Lab
  6. Building WPF Applications C# Part 2 Virtual Lab
  7. Building Microsoft WPF Applications Using Microsoft Visual Basic .NET