Windows Presentation Foundation (WPF)

WPF is a set of classes, tools, and controls with which developers can create even richer, more dynamic client solutions for Windows. This includes developing user experiences that combine traditional data view and entry with video, 3D graphics, shading, and vector-based scaling. The results are truly unique, visually appealing, rich applications.

WPF uses markup code to define the UI. This should be familiar to web developers. The markup is based on XAML, an XML-based definition language. The XAML is created for you using the Visual Studio WPF graphical designer (or a design tool now shipping with Visual Studio 2015 called Blend). At runtime, the .NET CLR processes the XAML. Unlike for HTML that requires a browser, the XAML-based UI is not bound by the limits of HTML inside a browser. Instead, it can create vector-based, hardware-accelerated user experiences.

Visual Studio provides a familiar experience for creating WPF solutions. You first define a WPF project and add WPF windows or pages to the project. When creating your solution, you select a project type based on whether the application runs as a browser add-in (uncommon) or as an install on a Windows machine. Figure 1.3 shows the WPF project templates based on a search for “WPF” in the dialog (upper right). Selecting WPF Application creates a basic WPF application that is pushed to or installed on a client machine. It might access local resources on the client.

Image

FIGURE 1.3 Creating a new WPF project.

The WPF Browser Application, in contrast, is meant to be deployed through a URL and run as a browser extension. The application, called an XBAP (XAML browser application), runs inside a sandbox. It does not have rights to the client machine and is cleaned up as part of the browser’s cache. The application does not require a download provided that users have the right version of the .NET Framework on their machine. It can work with the browser’s cookies and is supported by both IE and Firefox on Windows. (It does not run on other operating systems.)

Note that the other two application types in Figure 1.3 are WPF User Control Library and WPF Custom Control Library. Both are for creating reusable controls for WPF applications.

The next step in building your WPF window is to simply open it and drag and drop UI controls onto a design surface. One big difference for developers used to building WinForm applications, however, is that you now have control over the layout code (or XAML), which is more akin to designing a web form with Visual Studio. Figure 1.4 shows the XAML designer in action using the sample application built later in Chapter 21.

Image

FIGURE 1.4 Designing a WPF window.

Notice that the WPF controls are listed in the Toolbox on the left. Although they are similar to Windows and web controls, they are their own set of controls just for WPF. Also, notice how the designer has a split view between the design surface and the XAML. These views stay in sync as you develop your code. Finally, the properties window shown on the right provides a familiar experience for WinForms developers when editing the many properties of a selected control. We cover the WPF Form Designer in greater detail in Chapter 21.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset