Wednesday, 11 February 2009

Windows Presentation Foundation (WPF)


TLDR; Its actually rather good. Even 'the future'.

Ok. So I was asked before christmas to write a Charting library for integration into work's existing codebase. Specifically, .NET windows applications.

Seems simple enough right? Graph some lines. Right? Not this one. See, we want to be able to zoom and pan, analyse data, plot notes. All the things you want a graph to do. There are some issues with this:

  • Oh shi...this is going to require some maths
  • Matrices? :S
  • If I want decent, animated graphics, .NET's GDI+ isn't going to cut it.
The latter is the biggest issue. See, whilst GDI was managed code, GDI+ (perplexingly) is not even a managed wrapper. This makes it inherently slow to initialize good quantities of the API objects (brushes, colors, lines...). Interestingly, it doesn't even take advantage of hardware support - ouch.

I figured I could get around this. Maybe do something clever in GDI with timers, and clipping regions, and god forbid, dirty flags. GDI was having none of it, and with a 1024x768 chart, I was only getting 9-16fps, depending on backgronud activity. That is not a piece of code I want anywhere near customers, and it has stayed well within the bounds of proto-type. Not even on the source repository.

What to do? Some wise guy suggested WPF - after all it has hardware support and you can waste your time with lots of graphics stuff to avoid doing real work. Excellent!

So I grabbed myself a copy of WPF in c# 2008 2nd Edition and set about learning this API. Now, I'd dabbled before (messed around with the declaritive XAML) and came to the conclusion that it was unfinished junk. How wrong was I? Very.

See, now I know how this alien construct works. Listen up for the knowledge bomb: it is very powerful. This is where the future is definitly going and I want to see more people throwing Windows Forms to the wayside with gay abandon because that stuff is 'orrible.

No comments:

Post a Comment