WPF WTF #3: ListBox/View, Virtualising

5 September 2009    2 Comments

In .NET 3.5 SP1, WPF saw some fantastic performance increases including one of my favourites – the virtualising stackpanel (VSP). VSP’s meant that the items in a listbox/etc that aren’t on screen aren’t rendered – they’re virtualised. This provides memory and CPU performance increases.

VSP has two modes, Standard and Recycling, where the latter reuses the UI containers when it can, just changing the content, doing this saves even more memory.

And here is what happens when I enable VirtualisingStackPanel on a ListView in MahTweets.

image

That looks a little more than 140 characters per tweet – it starts combining the text in items. Fantastic.

If I use an ItemsControl (which Listbox/View are derived from), everything works fine – but ItemsControl has its own problems.

Note, this happens with any textbox/RTB I’ve tried in a ListBox/View with Recycling enabled, not just with my fancy ItemTemplates.


 

WPF WTF #2: Opacity

29 August 2009 , ,    No Comments

3866195696_feccd17706

On the left is WPF, on the right is WinForms, both have this.Opacity = 0.5; as the only code behind the button.

The WinForms example, as you can see, is semi-transparent and would shown whatever is behind it (if there was something behind it)

The WPF example, however, just "dulls" the contents of the Window rather than making the whole thing semi-transparent. The way to do it is to set AllowTransparency="true". However, that means WindowStyle must be set to None, which means you lose the chrome (the ‘glass’ around it), the minimise, maximise and close button, so you have to create and control those, as well as manually resizing the Window and manually controlling moving the Window.

I tried P/Invoking the Win32 libraries to set opacity and they work perfectly… on WinForms. They fail miserably in WPF.

I’m happy to be corrected if anybody knows a solution.

Opacity earns this weeks WPFWTF award and leaves us scratching our heads with the slogan, WinForms: Back To The Future.