All you ever wanted to know about WPF and Silverlight and XAML, Microsoft Expression Studio and more.

Improving Your WPF 3.5 SP1 Controls Performance

by Don Burnett

Simple tips for performance improvements with .Net 3.5 Service Pack 1 with controls (note this information is synchronized with beta 1)..

Controls that use the VirtualizingStackPanel Layout container..

TreeView Control

treeviewControlsp1

In the "Properties Panel" in Expression Blend Search for the  property:

VirtualizingStackPanel.VirtualizationMode

and again set it's property to be "Recycling"

The VirtualizingStackPanel.IsVirtualizing property must be set to TRUE as well.

Again setting these properties will cause you to see up to 40% scroll performance improvement in basic text scrolling, because while you scroll through items (in the control)  they are re-used when the UI elements that go out of view. If this option isn't specified, the items are destroyed and recreated as you scroll.

The XAML for your control will look something like this..

<TreeView VirtualizingStackPanel.IsVirtualizing=“true” VirtualizingStackPanel.VirtualizationMode="Recycling"  x:Name="TreeView1"/>

ListView

ListViewControl1

In the "Properties Panel" in Expression Blend Search for the  property:

VirtualizingStackPanel.VirtualizationMode

and again set it's property to be "Recycling"

The VirtualizingStackPanel.IsVirtualizing property must be set to TRUE as well.

Again setting these properties will cause you to see up to 40% scroll performance improvement in basic text scrolling, because while you scroll through items (in the control)  they are re-used when the UI elements that go out of view. If this option isn't specified, the items are destroyed and recreated as you scroll.

The XAML for your control will look something like this..

<ListView VirtualizingStackPanel.IsVirtualizing=“true” VirtualizingStackPanel.VirtualizationMode="Recycling" IsSynchronizedWithCurrentItem="True" x:Name="ListView1"/>

ListBox

ListBoxControl1

In the "Properties Panel" in Expression Blend Search for the  property:

VirtualizingStackPanel.VirtualizationMode

and again set it's property to be "Recycling"

The VirtualizingStackPanel.IsVirtualizing property must be set to TRUE as well.

Again setting these properties will cause you to see up to 40% scroll performance improvement in basic text scrolling, because while you scroll through items (in the control)  they are re-used when the UI elements that go out of view. If this option isn't specified, the items are destroyed and recreated as you scroll.

The XAML for your control will look something like this..

<ListBox VirtualizingStackPanel.IsVirtualizing=“true” VirtualizingStackPanel.VirtualizationMode="Recycling" IsSynchronizedWithCurrentItem="True" x:Name="ListBox1"/>

 

Deferred Scrolling

This option keeps the content in view as static until scrolling is complete, this is similar to how Microsoft Outlook scrolls. You can turn this capability on right inside Expression Blend.. Again use the search box in the properties panel to find the miscellaneous property on the ListBox Control called "IsDeferredScrollingEnabled" and check the checkbox.

deferredscrolling

DataGrid Control

The current beta doesn't provide us with this control to work with but I have been told that it will be available in the final release. This control will support the following performance improvements..

Container Recycling- Like earlier examples, recycling will improve performance.

Column Virtualization Extensions  new APIs added to VirtualizingStackPanel will exposes hooks to enable writing your own custom panel with virtualization in the horizontal direction. These could be used by a DataGrid control or by other custom panels.

Other New DataGrid Features (and some that can be used in other features)

MultiSelector support to handle multi-selection and bulk editing scenarios

IEditableCollectionView - New interface between data controls and data source that enables editing/adding/removing items in a transactional way.

StringFormat - shortcut to display data bound number as formatted text

Alternating Rows - Lets you set alternating properties on rows of ItemsControl (for instance: alternating background colors in a DataGrid)

Conversions for Null Values - Recognize null values in editable controls and convert them to  a value based on an appropriate type. This is really slick and will save a lot of people writing value converters. It also adds TargetNullValue property which lets you set any value as equivalent to “null”.

Item-Level Validation - By using Binding Groups this applies validation rules to an entire bound item. Another really slick function.

Code Free Enhancements

BitmapsEffects are the big ones.. Previously, all BitmapEffects were rendered in Software, now the Blur and DropShadow  BitmapEffects are Hardware Accelerated and rendered by the GPU. However there are still three effects that are still done through software rendering OuterGlow, Bevel, and Emboss.  BlurEffect, DropShadowEffect  are marked obsolete by their previously mentioned replacements. Some people have asked why? I am not sure totally the rational used, but some other folks have pointed out that they might be rendered obsolete anyway by the new GPU based hardware rendering which only works with DirectX 9 and above installed.

These effects in the past were mostly avoided, now they are extremely usable. In Silverlight for instance there are no BitmapEffects because there is no hardware accelerated rendering guaranteed available. So most people to stay as compatible as possible between a Windows Application and a Silverlight web application usually pre-render all of these as bitmaps anyway, so that's another approach you could take as well. In WPF there was also a way previously to "extend" the software rendered BitmapEffects but now that is obsolete as well.

WriteableBitmap is the WPF mechanism for drawing and updating a system-memory bitmap to the screen on a per-frame basis. This feature was available before, but in the past it  allocated a new bitmap with every frame update, which made it too slow for use in many situations. Now things like paint software and bitmap based animations are possible, due to the changes in the way it updates frames.  This makes things with complex geometries draw faster, so fractal renders and scatter plotting and charting applications for instance will see a big performance increase. When working with WriteableBitmap it's suggested that you use BGR32 or pBGRA32 pixel formats, as they are native to the renderer. Other formats, while they will still work get format converted frame by frame, causing yet a performance hit.

Z-Order Zee- Ooohh..

Microsoft has also significantly improved performance of WPF applications that continuously modify Z-Index property of Panel elements such as carousel controls. This is a welcome no code addition as things are very much sped up.

DIRECTX, Calling DIRECTX

With this release you can now have WPF and DirectX application, living working together in the same space. The new D3DImage class, allows you to overlay or blend Direct3D content interchangeably with WPF content (e.g. use the Direct3D surface as a brush for WPF content, or apply it as a texture within a WPF 3D scene ) without having any significant performance impact. HLSL DirectX Shader support has also been added.

 

» Similar Posts

  1. WPF Development- For Developers working together with a Designer
  2. The Future of Expression Blend
  3. XAML Powertoys Now with Silverlight 2.0 Support
There are no comments.

Comments are closed