Wednesday, March 24, 2010

Basics of WPF

WPF should not be used just to be able to have stylish looking UI with zoomable multi-state 3D buttons. WPF solves one of the biggest problems with user experience - data visualization. How can an application present complex data to the user that provides a highly flexible and customizable way for the user to find the right item doing very little work (or clicks) or minimal guidance on navigation.

Some of the good examples can be seen from the following link:

WPF is a developer’s paradise. The platform has many features which make *programming* more enjoyable and flexible.

- The databinding in WPF is far more powerful and comprehensive than in WinForms. This reduces the amount of code you need to write, and allows you to easily bind to pretty much anything.
- Routed events change the way you work with events. Now that events route down and up the element tree, there are many more ways to design code which deals with events for many controls, or controls which are loaded dynamically.
- Attached properties let you set a property on any object, even though the object does not expose that property. The possibilities are endless!
- Triggers are an extremely useful way to express conditional logic in markup. Very convenient.
- WPF is common technology which can be used for both Web and Windows .In WPF, you can create layout (User Interface) which can be used both in Window and Web application. (i.e. Before WPF, you will have to create separate layout for windows and web.)
- There is a nice feature of WPF is XPS (XML Paper specification) which means document looks same on screen and on a printer.
- One nice feature of WPF is that there is no need to write code for GDI+ and Direct 3D objects because it has been handled by WPF.
- WCF supports internationalization.
The new features of WPF can be used in this application are as follows:
- Freezable Objects:
Freezable objects provide special features that can help improve application performance. Examples of freezable objects include brushes, pens, transformations, geometries, and animations.

Visual tree and/or Logical tree:

XAML is natural for representing a user interface because of its hierarchical nature. In WPF, user interfaces are constructed from a tree of objects known as a logical tree.

Content Model :

In WPF, different classes of elements are categorized based on the type and number of their logical children. These logical children are also referred as the "content" of the control. WPF defines several different "content models" for various different classes of elements.
The controls that can contain a single item (single logical child of type Object) are called "content controls". These controls derive from the ContentControl base class. Controls that can contain a collection of items (many logical children of type Object) are called "items controls". These controls derive from the ItemsControl base class.
There are different kinds of content models available in WPF like Controls content model, Decoder content model, Panel content model, TextBox and TextBlock content model.

Use of Data Templates:

Data templates are a natural extension of styling controls and elements provided in Windows Presentation Foundation. Just as we can apply a visual Style to a user interface (UI) element, we can apply a DataTemplate that can determine both visual aspects of how the data is presented and how data binding accesses the presented data.

By applying different data templates to the same data, one can flexibly change the visual appearance of the data in the application. Data templates can be applied to both Windows Presentation Foundation content controls (for example: Button and Hyperlink) and items controls (for example: ListBox, ComboBox, and Menu). These controls have built-in support for applying such data templates.

Drag and Drop:

Drag-and-drop commonly refers to a method of user interface (UI) interaction that involves using a mouse (or some other pointing device) to select one or more objects, dragging these objects over some desired drop target in the UI, and dropping them.