Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

DataGrid Preview & Control Investments in WPF 3.5 SP1

WPF is proud to introduce the new DataGrid control and our control improvements for 3.5 SP1! In 3.5 SP1, the WPF Controls team invested heavily in improvements to our controls infrastructure to enable a performant, full-featured DataGrid in our next release. A CTP of our new DataGrid control is available on CodePlex.

The WPF team is excited to debut our new WPF DataGrid control! DataGrid is an essential feature for many applications and the WPF Controls team is working hard on developing a full-featured DataGrid equipped to meet our customers’ most common scenarios. To support the DataGrid initiative, in 3.5 SP1 WPF invested heavily in controls and data improvements to make our grid faster, more powerful, and more robust. These improvements included Item Container Recycling, Deferred Scrolling, Virtualization Extensions, MultiSelector, TreeView Virtualization, and more.

Read on for a preview of DataGrid features and an overview of the new controls and data features in 3.5 SP1. Also remember to try out the DataGrid CTP on our new WPF Codeplex site!

Introducing the WPF DataGrid

Here’s a quick list of the features you’ll find in the DataGrid CTP which is available now on the WPF Codeplex site:

  • Auto-generation of Columns. Simply hook up the DataGrid to an ItemsSource and at runtime it will auto-populate with variety of pre-built column types. You can also hook into column generation events to modify the columns as they’re created, or specify columns in the XAML.
  • Variety of Column Types. Text, CheckBox, ComboBox, Button, and Hyperlink columns are standard column types. You can also use the TemplateColumn to create your own custom column.
  • Row and Column Headers. Headers for both rows and columns can be toggled on and off.
  • Grid Lines. Horizontal and vertical grid lines can be toggled on and off and styled.
  • Column Width Behaviors. Columns can be set to auto-size to header or cell content, fill the remaining space (* behavior), respect max and min values, or set to an absolute width.
  • Cell Editing. Edit cell content and submit changes back to the database.
  • Selection. Row-only, cell-only, or row and cell selection can be enabled.
  • Keyboard Navigation. The entire grid can be navigated with keyboard only.
  • Column Resizing and Reordering. Columns can be resized and reordered programmatically or by the user through drag and drop in the UI.
  • Column Sorting. Columns support sorting and multi-sorting by end-user and programmatically.
  • Fully Style-able and Template-able. The DataGrid and all of its elements are fully style-able and template-able. Customize the look and feel of the grid, or make it look nothing like a grid at all (e.g. card view).
  • Add and Remove Rows. Add new items to the DataGrid or delete items from it. Customize the default value for a new row.
  • Row Validation. Create groups of validation rules to apply to rows.
  • Filtering/Grouping Support. Support for filtering and grouping data through CollectionViews.
  • Clipboard Operations. Built-in Copy support with extensibility for Cut and Paste.
  • Performance. Strong performance for scenarios with thousands of rows and many columns.

Features still to come include:

  • Readonly. Readonly at the grid and column level.
  • Row Details. Rows can expand to show and hide additional fields.
  • Hidden Columns. Hide columns without removing them from the collection.
  • New Column Types. Additional column types, including Image column.
  • Automation. Full automation peers for accessibility and testing.

What’s New in Controls for 3.5 SP1?

WPF’s goals for controls in 3.5 SP1 focused on supporting building DataGrid in our next release and improving the performance of our controls overall. One of our top priorities is to develop a high performance, full-featured DataGrid to support demanding LOB and ISV scenarios, and many of our improvements in controls focused in this area. We also wanted to make changes to our infrastructure to improve performance of all of our controls and achieve faster application start-up times.

Item Container Recycling

Item Container Recycling is a new feature which refers to a set of changes to VirtualizingStackPanel that allow it to recycle item containers. The current virtualization implementation generates containers as needed and throws them away when they are no longer in view. Creation of containers is expensive, so to improve performance, container recycling simply reuses a set of containers.

This is a performance optimization beyond the current ‘standard’ virtualization algorithm. Container recycling does not replace the ‘standard’ virtualization mode; instead, users will be able to select which virtualization mode they would like to use. For backwards compatibility, VirtualizingStackPanel will continue to use the standard virtualization mode by default. To turn on Item Container Recycling, application authors must set the new VirtualizationMode property to Recycling. Since VirtualizationMode is an attached property, it can be set directly on the ItemsControl hosting the panel.

Virtualizing TreeView

Before WPF 3.5 SP1, WPF flat lists (ListBox & ListView) supported UI virtualization, but hierarchical lists such as TreeView did not. TreeViews can contain many thousands of items and the old implementation kept all elements in the entire hierarchy in memory, rendering some scenarios infeasible (such as a Windows Explorer scenario with thousands of nested items or an SDK help structure with over a hundred thousand top-level items). Virtualizing TreeView eliminates these problems by adding UI virtualization for TreeViews. Setting the IsVirtualizing property to true will turn on this feature.

MultiSelector

MultiSelector is a new primitive control which publicly provides multi-selection functionality and the ability to perform bulk selection. MultiSelector exposes the necessary Selector internals for implementing classes with different selection models and bulk selection methods, and custom control authors can use MultiSelector to build multi-selection based controls without subclassing one of Selector’s subclasses. MultiSelector is not designed to be a standalone control, so the most common usage of this control will be in subclasses such as DataGrid, ListBox, and ListView to select entire rows and columns.

Deferred Scrolling

Deferred scrolling is a perceived performance improvement for ItemsControls such as ListBox. The default behavior of ScrollViewer in WPF is "live" scrolling, where the user is able to see the contents of the scroll viewer move while dragging the thumb of a scroll bar. This can be problematic for controls such as ListView and DataGrid, which often have complex item templates and use virtualization. In these cases, the amount of processing required to refresh the view with new items consumes too large an amount of time for the UI to appear snappy. To the end-user, the UI could feel sluggish and non-responsive. Deferred ("non-live") scrolling is an alternative scrolling behavior where the contents of the scroll viewer remain static until the user releases the mouse button (similar to the behavior of the Outlook 2007 Inbox). In the absence of other performance improvements, having non-live (deferred) scrolling could be beneficial for improving the end-user’s perception of scrolling performance.

Deferred scrolling can be enabled by the setting the IsDeferredScrollingEnabled property of the ScrollViewer on any ItemsControl to true.

Virtualization Extensions

Virtualization Extensions is one control improvement which was designed with DataGrid in mind. This feature exposes hooks to enable writing a custom panel which can handle multidimensional UI virtualization. We will use this feature to implement Column Virtualization for the DataGrid, and application authors can use the Virtualization Extensions to write custom virtualization panels which handle horizontal and vertical virtualization. For DataGrid, this means that performance in scenarios with hundreds or thousands of columns will be greatly improved.

IEditableCollectionView

IEditableCollectionView is a new interface that was designed with the intention of enabling communication between a control such as DataGrid and a data source that allows editing of the data such as adding/removing/editing items. IEditableCollectionView allows adding/removing/editing items in a transaction. This interface will mainly be used by application authors who are building custom CollectionViews.

String Format

String Format makes it possible to convert a data bound number (such as 10) into formatted text (such as $10.00) when it is displayed without having to write a custom ValueConverter. The most common usage of formatting functionality will be on Bindings and MultiBindings, or as a convenience on certain controls. String Format can be used directly from markup.

Alternating Rows

A popular feature in lists is the ability to color alternating rows with two or more different colors in order to enhance readability and offer control over the grid’s look and feel. The Alternating Rows feature makes it easier for application authors to set alternating properties (such as background or foreground color, font style, etc.) on the rows of an ItemsControl. When an AlternationCount is set on an ItemsControl, each item in the control will receive an alternating value of AlternationIndex, which can then be used in Triggers or with a ValueConverter to apply alternating properties.

Null Value Conversion

The Null Value Conversion feature is designed to make it easier for WPF applications to recognize and convert null values in editable controls without requiring application authors to write their own custom converters. The most common scenarios which will make use of Null Value Conversion are scenarios where WPF controls are data bound to data sources which have different null types than the data being displayed in the controls. Many common null types will be recognized and converted automatically, and developers also have the ability to use the new TargetNullValue property to specify a value which is equivalent to null.

Binding Group

Binding Group enables item-level validation, where a set of validation rules are grouped together and used to validate the data entered across multiple controls. This is useful for scenarios such as validating data entered into forms, where there are inter-dependent fields which need to be validated before the user can submit the form (for example, checking that "Age" is less than "Years of Employment"). The DataGrid will use Binding Group to enable row-level validation.

Learn more

If you’re interested in learning more about the DataGrid CTP, please visit our Codeplex site. If you’d like to learn more about controls in WPF, please see the Controls documentation on MSDN. You can also view the "DataGrid Preview" walkthrough video.

Comments: 0

You must Login to comment.

Featured Item

Page view counter