Sunday, April 1, 2007

VSLive, Day 5, All about WPF

So, I'm very excited about Windows Presentation Foundation. Therefore I spent the last (workshop) day allday with Billy Hollis in his session about WPF, named: From the Ground up.

WPF is officially released. The tooling however to create i.e. XAML pages is in a very early state. The tools available at the time of writing can be found at the bottom of this page under resources. Therefore the amount of time it needs to write a WPF enabled application takes roughly 3 times longer than it should take, because of minimal tooling support. However it can still make sense to develop a WPF application, i.e. when the requirements of the app can be far more easily covered by an application using WPF.

Why is WPF such a revolution in UI design? The last transistion of the UI was 20 year ago. Every UI up until now was based upon GDI, invented in 1984. WPF is build on top of DirectX, which is capable of using all the power of graphic cards that are available to those stunning games also.

Furtermore it is vector based, making it possible to zoom without loss of detail.

In an attempt to fill in the gap between the rich UI experience on with Windows Forms on the web, a subset of WPF will be created by Microsoft, which is currently known as WPF/e (the e stands for everywhere). Some features are missing, like i.e. 3D. But WPF/e does not require .NET 3.0. It's even platform independent. It therefore supports MAC and Linux also. WPF/e will be introduced before the end of 2007. It will be a serious competitor for the nowadays widely used Flash.

User interfaces can be specified by XAML files (pronounced "Zammel"). XAML is an XML file, that describes the user interface as an hierarchy of (visual) elements. XAML is a big step towards declarative programming- Decalre what you want, not how it happens.

WPF Application Model:

  • System.Windows
  • Application objects as entry point
    - StartingUp, ShuttingDown events
    - Run method, MainWindow property, etc.
  • Visual elements
    - Page, Window

Sampleviewer (installed with "Visual Studio 2005 extensions for .NET Framework 3.0", currenlty a CTP) takes you around all the features of WPF one by one.

Differences between WPF and Windows Forms

  • No MDI in WPF
  • No build-in data grid in
  • WPF has "container/control" distinction
    - No Controls collection"Visible" > "Visiblity" in WPF
    - "Hidden" takes up space
    - "Collapsed" doesn't take up space
  • Absolute position in WPF is the exception, not the rule
  • Sizing and positioning are in device independent units (1/96 inch) in WPF
  • Scrolling is external to controls
    - ScrollViewer element
  • Non-containers can only hold one element
    - Called the controls "content"
    - Set with the Content property
  • Content can be any visual element
  • Content can itself be a container

Databinding:

  • Create a collection of stuff
  • Bind it to the context of the window
  • Bind controls to the item properties
  • Add navigation, filtering, sorting, and so forth

XAML Based Application (XBAP) are WPF enabled applications which can be used within a browser.

  • Act a lot like HTML pages
    - Non-installed, served from a web server
    - Browser hosted on the client (take over the whole browser surface)
    - Run in a security sandbox
  • Have their own project type under Visual Studio
    - Caution - March CTP bug on Vista
  • Published to Virtual Directory on web server
  • "NavigateURI" attributed used on links to navigate pages
  • App has read permissions to its original web directory
  • Can use IsolatedStorage for caching and state management.

Animation can consist of:

  • 2D and 3D Transforms
  • ...

Styles can be applied on the fly trough code or to triggers (i.e. hovering a button).

Ink is enabled in WPF (on Windows XP, after installing appropriate libaries).

3D Rendering of surfaces

  • Use full 3D capabilities underneath
  • Compose surfaces out of triangles
    - Triangle is the only primitive
    - Created as of MeshGeometry3D
  • Viewport3D is visual element to render 3D objects on screen in 2D
    - Apply camera angle, for example, to this viewport
  • Exporter for Autodesk 2DS Max is not (yet) official available

Types of events within the tree hierarchy of an WPF application

  • Direct (only on element)
  • Bubbling (move up the tree)
  • Tunneling events (from outside into the tree and down to the elements)

Tools for XAML:

Other resources:

Other blogs:

Examples of XAML Based Applications:

  • British Library, using WPF and thus requires Windows and .NET 3.0 installed at the client PC.

2 comments:

FW said...

Thanks for your resourceful post. Could you help me understand “WPF/e is a subset of WPF”? WPF/e uses XMAL and Javescript, not C#. The API is different. I agree its functionality is a subset of WPF; but have hard time to understand the API is a subset.

DirectX is a big family. As I know, WPF uses Direct3D. Any other parts?

Does WPF use WinForms underneath? For example, the namespace of WPF user control is System.Windows.Controls.UserControl?.

Jan van de Pol said...

You are right in the assumption that WPF uses DirectX / Direct3D, and only that. WPF isalso fully released, while WPF/e is still under development. WPF/e is going to be supported on non-Windows platforms also, like Unix/Linux and MAC.

WPF/e will provide a subset of the functionality that WPF offers, but not trough the same API, technically not possible as far as I can see, because of the multiplatfrom. The subset leaves out 3D for instance.

WinForms is not used underneath. WinForms is based upon GDI (GDI+). UserControl in WinForms is in the System.Windows.Forms.ContainerControl. See the difference in namespace.

Note that if your target audience uses Windows PC's, then you can develop a Browser Application also with the full WPF. Clients need to have .NET 3.0 installed in that case.

Hope this helps you little better to understand.