My focus is on making software, coaching Agile/Scrum teams, and being a husband and father--definitely not on blogging--so please do not expect very frequent posts here.

Monday, April 11, 2011

How can I write WPF efficiently?

When I first learned about Microsoft's then-new framework for developing desktop applications, WPF, I thought that one of the biggest benefits of it would be its efficiency.  After all, I already know what the GUI controls and elements were that I wanted to use--I just have to slap them all on the page and then wire up all my bindings right, and I'll be done.  After that, I learned about the MVVM pattern, which promised clean separation of concerns within my WPF app.

I thought this was going to be great!  I got into creating several different admin and data entry WPF apps with my team at work, and thus I began to crank out working software with robust but simple GUIs, right?

Not so fast, there, cowboy coder. My experience is that writing WPF is S-L-O-W.  

Well, at least the way I do it.  You see, after I have a picture of my GUI on a whiteboard, I code up the XAML with the controls that I want.  This part, as expected, is fast--laying out the whole of a window is pretty quick. After that, its all the little stuff you want these elements to do takes awhile. I always seem to want to make this text bold in some cases; show a red error box in these other cases.

Then things unravel: this binding isn't working right over here--I have to write a converter and adjust the layout for the right values. Whoops, I forgot that extra NotifyPropertyChanged there. Oh, and I want to use a different template in this state vs. that, so I have to figure out what I can use to swap the templates in certain situation.  This data is coming in asynchronously, so I need to make sure the right thing is happening on the right thread and that Property gets NotifyChanged as well.  Crap, when I maximize my window, it doesn't stretch like I thought it would--must be because its container height isn't defined, but I don't want to define that, so I have to make it stretch in its parent.  Oh, now I really want to make a user control out of this stuff over here, so I better implement some dependency properties...

On and on I go, spending hours and days on stuff that just feels so small and minor. I soon resort to cutting usability features and look-and-feel enhancements because this is taking just too darn long.

Does anyone have any tips or principles I need to try in order to write WPF efficiently?  I'm off to search the tubes for some thoughts.

Edit: added link for StackOverflow question.

No comments:

Post a Comment

Post a Comment