What's New in WPF Version 4.5

What's New in WPF Version 4.5

This topic contains information about new and enhanced features in Windows Presentation Foundation (WPF) version 4.5.

This topic contains the following sections:

Ribbon control

WPF 4.5 ships with a Ribbon control that hosts a Quick Access Toolbar, Application Menu, and tabs. For more information, see the Ribbon Overview.

Improved performance when displaying large sets of grouped data

UI virtualization occurs when a subset of user interface (UI) elements are generated from a larger number of data items based on which items are visible on the screen. The VirtualizingPanel defines the IsVirtualizingWhenGrouping attached property that enables UI Virtualization for grouped data. For more information about grouping data, see How to: Sort and Group Data Using a View in XAML. For more information about virtualizing grouped data, see the IsVirtualizingWhenGrouping attached property.

New features for the VirtualizingPanel

  1. You can specify whether a VirtualizingPanel, such as the VirtualizingStackPanel, displays partial items by using the ScrollUnit attached property. If ScrollUnit is set to Item, the VirtualizingPanel will only display items that are completely visible. If ScrollUnit is set to Pixel, the VirtualizingPanel can display partially visible items.

  2. You can specify the size of the cache before and after the viewport when the VirtualizingPanel is virtualizing by using the CacheLength attached property. The cache is the amount of space above or below the viewport in which items are not virtualized. Using a cache to avoid generating UI elements as they’re scrolled into view can improve performance. The cache is populated at a lower priority so that the application does not become unresponsive during the operation. The VirtualizingPanel.CacheLengthUnit property determines the unit of measurement that is used by VirtualizingPanel.CacheLength.

Binding to static properties

You can use static properties as the source of a data binding. The data binding engine recognizes when the property's value changes if a static event is raised. For example, if the class SomeClass defines a static property called MyProperty, SomeClass can define a static event that is raised when the value of MyProperty changes. The static event can use either of the following signatures.

  • public static event EventHandler MyPropertyChanged;

  • public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;

Note that in the first case, the class exposes a static event named PropertyNameChanged that passes EventArgs to the event handler. In the second case, the class exposes a static event named StaticPropertyChanged that passes PropertyChangedEventArgs to the event handler. A class that implements the static property can choose to raise property-change notifications using either method.

Accessing collections on non-UI Threads

WPF enables you to access and modify data collections on threads other than the one that created the collection. This enables you to use a background thread to receive data from an external source, such as a database, and display the data on the UI thread. By using another thread to modify the collection, your user interface remains responsive to user interaction.

Synchronously and Asynchronously validating data

The INotifyDataErrorInfo interface enables data entity classes to implement custom validation rules and expose validation results asynchronously. This interface also supports custom error objects, multiple errors per property, cross-property errors, and entity-level errors. For more information, see INotifyDataErrorInfo.

Automatically updating the source of a data binding

If you use a data binding to update a data source, you can use the Delay property to specify an amount of time to pass after the property changes on the target before the source updates. For example, suppose that you have a Slider that has its Value property data two-way bound to a property of a data object and the UpdateSourceTrigger property is set to PropertyChanged. In this example, when the user moves the Slider, the source updates for each pixel that the Slider moves. The source object typically needs the value of the slider only when the slider's Value stops changing. To prevent updating the source too often, use Delay to specify that the source should not be updated until a certain amount of time elapses after the thumb stops moving.

Binding to types that Implement ICustomTypeProvider

WPF supports data binding to objects that implement ICustomTypeProvider, also known as custom types. You can use custom types in the following cases.

  1. As a PropertyPath in a data binding. For example, the Path property of a Binding can reference a property of a custom type.

  2. As the value of the DataType property.

  3. As a type that determines the automatically generated columns in a DataGrid.

Retrieving data binding information from a binding expression

In certain cases, you might get the BindingExpression of a Binding and need information about the source and target objects of the binding. New APIs have been added to enable you to get the source or target object or the associated property. When you have a BindingExpression, use the following APIs to get information about the target and source.

Up Next
    Ebook Download
    View all
    Learn
    View all