advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the sample C# code.
Download the sample VB.NET code.
CoDe Magazine
Which to Use: WPF or Windows Forms?
Partners & Affiliates
advertisement
advertisement
CoDe Magazine
Subscribe to CoDe Magazine
Average Rating: 5/5 | Rate this item | 2 users have rated this item.
 Print Print
 
WPF Meets the iPhone
Find out how to add iPhone-like UI features to your WPF applications. 

advertisement
he 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. 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, here's 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 integrated into .NET 3.5.

WPF is preinstalled on Windows Vista and is available for installation on Windows XP Service Pack 2 and Windows Server 2003.

Author's Note: Older versions of Windows such as Windows 98 and Windows 2000 cannot run WPF, so if you need to support older operating systems you can't use WPF.

WPF Benefits
WPFs benefits 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 because WPF is resolution independent.
  • WPF's 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/WCF extensions for Visual Studio 2005 support 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, XBAPs are hosted within Internet Explorer. XBAPs are not web applications. They are Windows applications hosted in an Internet Explorer browser. Unlike WPF standalone applications though, 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. 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!

Microsoft Expression Blend
In a perfect world you would just be able to use Visual Studio 2008 to create your WPF applications. However, there were some major pieces left out of Visual Studio 2008 that make it difficult to work with WPF. Fortunately, you can find most of these missing pieces in Expression Blend.

For example, when you edit a WPF user interface in Visual Studio 2008, the property sheet doesn't have an events button (lightning bolt) as it does when editing a classic Windows Forms user interface. Fortunately, the Expression Blend Properties window does have an events button. Also, there is no easy way to bind user interface controls to data or business entities in Visual Studio 2008. Again, Expression Blend picks up the slack and has an IDE for data binding the user interface. As you will see in this article, Expression Blend also has a far better set of tools for creating animations, as well as for designing and rendering the user interface. On the other hand, Visual Studio 2008 has a key advantage over Blend in its IntelliSense support when editing XAML files manually—which you will need to do often when using Visual Studio 2008 alone.

Based on the more complete feature set of Expression Blend, in this article you will start out using Expression Blend to create and edit a WPF application, and then you will see how it works in conjunction with Visual Studio 2008. As you will see, Expression Blend can create and edit Visual Studio 2008 solutions and projects. However, it doesn't have a code editor, so whenever you need to add code to your project you are automatically taken to Visual Studio 2008.

Editor's Note: This article was first published in the March/April 2008 issue of CoDe Magazine, and is reprinted here by permission.

  Next Page: Creating a WPF Host Application


Page 1: IntroductionPage 4: Creating the iPhone Status Bar
Page 2: Creating a WPF Host ApplicationPage 5: Creating the Main Button Panel
Page 3: Creating Application ResourcesPage 6: Working with Animations
© Copyright Component Developer Magazine and EPS Software Corp., 2006
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES