What's New in WPF Version 4.5
- 6 minutes to read
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.
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
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.
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.
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.
As a PropertyPath in a data binding. For example, the Path property of a Binding can reference a property of a custom type.
As the value of the DataType property.
As a type that determines the automatically generated columns in a DataGrid.
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.