Windows Presentation Foundation

Windows Presentation Foundation

Note: This page is currently a stub article. Add information as you can.

 


Introduction

Windows Presentation Foundation (WPF) is a client programming interface and presentation system for building Windows applications with a new, stunning user experience, introduced for the first time in Windows Vista and .NET Framework 3.0.

The WPF core is a resolution-independent and vector-based rendering engine that is built to take advantage of modern graphics hardware. WPF extends the core with a comprehensive set of application-development features that include Extensible Application Markup Language (XAML), controls, data binding, layout, 2-D and 3-D graphics, animation, styles, templates, documents, media, text, and typography.

WPF is included in the Microsoft .NET Framework, so you can build applications that incorporate other elements of the .NET Framework class library.

Styles & Control Templates

 
One of the most powerful and important aspects of WPF to thoroughly understand is Styling and Templating.
 
A control has a Control Template, which defines what is in the control's user interface and how it is layed out.
A Control (or UserControl) exposes a number of Dependancy Properties, which can be used in binding, like TextBox.Background (colour) or TextBox.Text.
 
A Style is a collection of Dependancy Property Setters and various Trigger types, which can be applied to some (explicit style) or all (implicit style) controls of that style's TargetType
 
If you give the Style an x:Key, it is called an "explicit style" and you attach the style to selected controls. 
If you do not give the style an x:Key, so it only has a TargetType reference, it is called an "implicit style", and it will apply to all controls of that same TargetType type.
 

Triggers

 
The use of Triggers and Visual States mean UI change logic can stay in the UI, and not clutter up the code.

Whereas a Winform CheckBox would need an event and code to open a new section of the page, this can now all be done on the actual page.

With all the UI logic being handled in the UI, you can simply lift off the page and use another page with completely different logic.
 

WPF Design Patterns

There are two main styles of coding a WFP application (not including third party frameworks like Dependancy Injection frameworks).


Code Behind

This method involves simply placing all your code and event handlers in the .xaml.cs partial class file, this is the same style of coding as for WinForms. This has many benefits, as you have direct access to the controls and events.

The downside is [in many people's opinion] messy code code that is not reusable, and applications that are not reskinnable.

A Winform Developer will usually start with code-behind programming, but it can encourage bad habits, like traversing the visual tree (rows and cells) of a DataGrid to read and change properties, instead of working with the source data (which was bound to the control anyway).

Model View ViewModel (MVVM)

This method involves completely seperating the data and business logic from the user interface.

Data is simply "presented" in a ViewModel, which the View (Page/Window) consumes.

The advantage is an easily reskinnable application, less dependancies, separation of concerns and "loose coupling" the actual application from the data.

Almost every feature that was lost from working within the actual UI partial class (like events) can be replaced by a command, attached property or attached behaviour.

Evrything in the UI (View) is bound to a property of the ViewModel, which makes the application much more testable, as every change of the UI is represented by a neatly organised property of the VM.

 

Community Resources

MSDN Library Web Pages

Technical Articles

Books

Videos

 

Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Patris_70 edited Revision 15. Comment: deleted (en-US) from title

  • Luigi Bruno edited Revision 10. Comment: Added three links in the "Technical Articles" section.

  • Luigi Bruno edited Revision 9. Comment: Edited articles's sections. Edited title and tags list.

  • Ed Price - MSFT edited Original. Comment: Stubbage

Page 1 of 1 (4 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Ed Price - MSFT edited Original. Comment: Stubbage

  • Added TOC.

    Added "Community Resources" section and "Books" section.

  • Edited tags list.

  • Added "Technical Articles" section and a few links within.

  • Added a "Videos" section and a link within.

  • Luigi Bruno edited Revision 9. Comment: Edited articles's sections. Edited title and tags list.

  • Luigi Bruno edited Revision 10. Comment: Added three links in the "Technical Articles" section.

  • Added Styles & Templates, Triggers, Design Patterns

  • Patris_70 edited Revision 15. Comment: deleted (en-US) from title

Page 1 of 1 (9 items)