.NET

What's New In WPF 4.5

A ribbon control, new dispatcher methods, and delayed data bindings head the list of new features in the recent update to Windows Presentation Foundation. Here's how to use them.

In Using Asynchronous Methods in ASP.NET 4.5 and in MVC 4, I provided examples of the new asynchronous methods introduced in .NET Framework 4.5, and I showed a WPF sample application. In this article, I present detailed examples of the most useful new features and improvements in WPF 4.5. The first of these is a new ribbon control.

Ribbon Control in WPF 4.5

WPF 4.5 includes a built-in Ribbon control (finally!), so there is no need to incorporate separate downloads for your project. Microsoft Office, SharePoint, and Office 365 make extensive use of Ribbons, and therefore, it usually necessary to use a Ribbon control in WPF applications.

By default, a new WPF project that targets .NET Framework 4.5 won't include the necessary library reference to start using the Ribbon control and all its related sub-controls. Thus, before adding a Ribbon to your application, you must add a reference to the System.Windows.Controls.Ribbon library (see Figure 1).

Figure 1: Adding a reference to System.Windows.Controls.Ribbon in a WPF 4.5 application.

Once you've added this reference, you can input the XAML code to define a new
Ribbon control and you will see it in the XAML preview (also known as the
designer). By default, the Ribbon is empty (see Figure 2):

The most convenient way to understand both the power and flexibility of the
Ribbon control is to use a simple yet complete example that takes advantage
of many of the Ribbon sub-controls. I use a WPF 4.5 application that has the
following PNG images in the ribbon. I've located them in an Images folder
(see Figure 3):

blue.png

copy.png

cut.png

format_painter.png

green.png

help.png

options.png

paste.png

quit.png

red.png

redo.png

save.png

undo.png

Figure 3: The Ribbon control will use the PNG images within the Images folder as icons.

The following code defines a Ribbon and includes many of its sub-controls (see Figure 4):

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!