Introduction to .NET Framework 3.0/Windows Presentation Foundation

Windows Presentation Foundation (codenamed:Avalon) is a new feature (a presentation platform) introduced with .NET Framework 3.0 which supports the creation of documents containing high-resolution pictures and graphics. WPF is also responsible for the integration of pictures and media in ordinary documents. At present, the component performing this function is Windows Forms.

What is Windows Presentation Foundation
A productive, unified approach to UI, media and documents to deliver unmatched user experience

WPF Infrastructure
The Presentation Foundation contains classes to create 'Print' and 'File Open' dialog boxes, script new windows, etc. It makes use of four specific classes most of the time:


 * UIElement
 * FrameworkElement
 * ContentElement
 * FrameworkContentElement

These classes help in building an effective and easy to use user interface. The WPF UI is usually in the form of a Element Tree. Element Trees used in WPF are of two types:


 * Logical Tree
 * Visual Tree

Element Trees are usually implemented in XAML by dragging and dropping and creating relationships between the concerned elements. In code, they depend on how we give property values for properties.

The logical tree involves creating a tree structure by adding a listbox tag and list items inside the tag. In the case of a DockPanel we use Children property.

The visual tree is mainly used by programmers who want to meddle with the underlying low-level components of the program.

Combination of Markup and Programming
While the usage of a programming language as C# is best recommended for programming logic, the usage of markup languages is recommended for texts and UIs.

In earlier versions of the .NET framework, the designer part was separate from the code. However, in .NET 3.0, both the designer part programmed in XAML and the logic programmed in C# are included in the same code.

XAML File  Click Me! 

C# code-behind file using… namespace Button {	public partial class Default : Panel {    // Event handler void Button_Click (object sender, System.Windows.Controls.ClickEventArgs e) 	      {    btn1.Background = System.Windows.Media.Brushes.Red;  } } }

Graphics
Windows Presentation Foundation enables the user to create graphic applications of high-quality. You could add existing or create custom buttons using tag, create docked panels, 2D and 3D graphical images, use color picker controls, create or modify images, videos, create custom medi players, etc.

Drawing Object Model
The WPF graphics system offers a completely new programming style. With Win32-based UI technologies, if you want to draw customized graphics, you must write code that responds to repaint requests, drawing the details on demand. This code effectively paints directly to the screen. If that part of the screen becomes obscured by another window and then uncovered, Windows sends a message requesting that this be redrawn. If you want to change the appearance of your graphics, you need to instruct Windows to invalidate the relevant areas of the screen in order to initiate a repaint.

Richly Formatted Text
WPF also helps us create formatted text easily and hence rich formatting could be used. The contents are enclosed within a tag.

User Events could be executed easily by using triggers which are specified using the tag. Apart from this, there are many other new innovations in WPF.

Templates and Styles
There are two types of templates: Data Templates and Control Templates. Control Templates define the control and the visual structure of the control.

Syntax: ControlTemplate x:Key=“MyButton” TargetType=“{x:Type Button}”>     

On the contrary, data templates contain specifications about the data to be stored.

Syntax:

  

Styles are used to specify the syles of buttons used.

 

Styles can also be based on other styles.

Style x:Key=“MyStyle” BasedOn=“{StaticResource BaseStyle}” />  

Documents
WPF supports three kinds of documents


 * Fixed Documents
 * Flow Documents
 * XPS Documents

WPF has introduced new concepts which make the integration of text with media files easier. WPF also supports a variety of fonts which were not handled by earlier versions.

Fixed Documents
Fixed Documents are representative of WYSIWYG ("What you see is what you get") principle. Here, what you see on the screen indicates the actual layout that you will get on paper when the page is printed. Hence, even slight changes to the layout shall be critical.

Flow Documents
Flow Documents are those document formats which adjust their size, readability, dimensions, etc. depending on the size of the screen. Documents of this type are also supported by WPF.

XPS Documents
XPS documents are those which are exact representations of how the document shall look on paper. They resemble scanned images of the document itself.

Benefits

 * Ease of Use -- Learn ability, Performance, Reliability, Security, Optimized form factors, Legibility / Readability, Relevance / Contextualization
 * Richness -- Graphics & Media, Data Visualization, Higher Fidelity Information, Globalization, Accessibility, Hardware & Printing Integration.