WPF Meets the iPhone
The iPhone is one of the most compelling and exciting user interfaces to appear on any consumer electronic device, with many innovations that make it a pleasure to use. How can you deliver a similar experience with your .NET applications? This article demonstrates how you can implement these features in your .NET applications in a step-by-step format as you recreate the iPhone interface using Windows Presentation Foundation (WPF) technology with both Visual Studio 2008 and Microsoft Expression Blend.
Just when you finally master creating Windows applications using .NET Windows Forms, Microsoft comes out with a new replacement technology-Windows Presentation Foundation-that is completely different in just about every possible way and requires a significant learning curve! Fortunately, this break with the past comes with tremendous benefits and the ability to vastly improve the quality of user interfaces you deliver to your end users. Before jumping into recreating the iPhone interface, let’s first get a quick WPF primer.
What Is Windows Presentation Foundation?
Windows Presentation Foundation (WPF) is Microsoft’s powerful new technology for building Windows user interfaces. WPF is one of four technologies (Windows Presentation Foundation, Windows Communication Foundation, Windows Workflow, Windows CardSpace) released by Microsoft as part of the .NET 3.0 Framework that are now a part of .NET 3.5.
WPF is preinstalled on Windows Vista and is available for installation on Windows XP Service Pack 2 and Windows Server 2003. Older versions of Windows such as Windows 98 and Windows 2000 cannot run WPF! Unfortunately, if you need to support older operating systems you can’t use WPF.
The benefits WPF provides are well worth the time and energy you need to spend in yet another learning curve:
- With little or no code you can display eye-catching animations and transitions that place your user interface head and shoulders above your competitors
- WPF vastly improves the speed of the user interface whether you are creating standard business applications or using complex animations
- Unlike Windows Forms technology where you wrestle with creating a user interface that looks good regardless of the end user’s settings, WPF user interfaces easily resize and reformat to display any DPI or font size, dynamic content, and different languages due to its resolution independence.
- Its declarative user interface and separation of layout from code makes it easy for a designer to create the look and feel and the developer to implement the user interface behavior
- You can display rich text content anywhere in the user interface
- You can easily implement audio and video in your application
- As far as end users are concerned, your user interface is the application. Anything you can do to improve the user experience can translate into user satisfaction and increased sales!
So Long GDI+, Hello DirectX
WPF offers so many benefits because it uses DirectX technology rather than using GDI+ as does Windows Forms. The technology in GDI+ is over 10 years old and doesn’t take advantage of modern advancements in display technologies. In contrast, WPF, and in turn DirectX, offloads as much processing as possible to the Graphics Processing Unit (GPU) on your computer’s graphics card, providing a tremendous performance boost.
Getting Started in Windows Presentation Foundation
Although you can create WPF applications using the .NET 3.0 Framework in conjunction with Visual Studio 2005 and WPF extensions, I do not recommend it. The WPF extensions support for WPF is extremely weak and not worth the effort. Instead, you should go directly to the following technologies:
- .NET 3.5 Framework
- Visual Studio 2008
- Microsoft Expression Blend 2 (December 2007 CTP)
As I write this article, Microsoft Expression Blend 2 is still in Community Technology Preview (December 2007 CTP), however it’s still worth using this version because it has support for Visual Studio 2008 and contains many important features not present in Expression Blend Version 1.
If you really can’t move to Visual Studio 2008 yet, you can still follow the step-by-step instructions in this article by using Visual Studio 2005 and installing the WPF/WCF Extensions for Visual Studio 2005 which you can download from Microsoft’s web site (http://www.microsoft.com/expression/). You won’t see many differences between Visual Studio 2005 and Visual Studio 2008 as you go follow the step-by-step instructions in this article since it only uses Visual Studio for editing code, but as mentioned previously, for regular WPF development you should definitely move to Visual Studio 2008 as soon as possible.
WPF Standalone Applications vs. XBAP Applications
There are two main types of WPF applications-WPF standalone applications and XAML browser applications (XBAPs).
WPF standalone applications are the equivalent of a Windows Forms application. You install this standalone Windows executable on a computer using an MSI, XCOPY or ClickOnce technology and it runs in a standard Window. By default, it executes with full trust.
In contrast, a XAML browser application is hosted within Internet Explorer. XBAPs are not web applications. They are Windows applications that are hosted in an Internet Explorer browser. By default, they run in the Internet zone which restricts access to system resources such as the file system (including databases) or the Windows Registry. Although you can elevate the permissions on an XBAP application, rather than forcing the issue, you should instead create a WPF standalone application.
These restrictions severely limit the kinds of applications you can create as XBAPs. That said, there are some incredible XBAP applications out there. One of the best examples is the Museum of London’s Turning the Pages application which is an incredible showcase of WPF capabilities: http://www.bl.ui/onlinegallery/ttp/ttpbooks.html. When you go to this site, make sure you click on the link that takes you to the WPF version of the site (rather than the Flash version). You can turn the pages on famous works by the likes of Leonardo da Vinci and Lewis Carroll-you can even turn on audio and listen while Alice in Wonderland is read to you!
By: Kevin McNeish
Kevin McNeish is President of Oak Leaf Enterprises, Inc, and chief architect of the MM .NET Application Framework. He is a Microsoft .NET MVP and a well-know INETA speaker and trainer throughout North America and Europe including VSLive!, DevTeach (where he serves as one of the .NET chairs), SDC Netherlands, and Advisor DevCon. He is co-author of the book Professional UML with Visual Studio .NET, author of the book .NET for Visual FoxPro Developers, writes articles and has been interviewed for .NET Rocks! He spends about half his time on the road training and mentoring companies to build well-designed, high-performance .NET applications.
Windows Presentation Foundation is the future of Windows application development at Microsoft. It is a replacement technology for Windows Forms with a hefty learning curve but generous returns on your investment.