Silverlight Masterclass – Discounts for NxtGenUG Members

Introduction

Shawn Wildermuth’s “Silverlight Tour” is coming to the UK, in the guise of the Silverlight Masterclass, and NxtGenUG members can receive £50 off the course price (in addition to the current “early bird” offer if you qualify for that).

The 3 day developer course looks quite comprehensive, starting with Silverlight, XAML and Blend basics on day one, working with data on day two, and finishing off with more advanced topics like MVVM, MEF and PRISM on day three. It’s great to see some patterns and practices coverage in a Silverlight course, especially given my recent experience trying to recruit Silverlight developers!

In addition to the discounts you can also win a free ticket to one of the courses by blogging about it yourself using the text from the “pitch” below. For more details on the competition take a look at Ian Blackburn’s blog entry.

The Pitch

The Silverlight Tour comes to the UK – and it’s called the Masterclass!

This 3 day hands-on training with both designer and developer tracks looks awesome and (uniquely) has two expert trainers per course.

Currently scheduled in London, Manchester, and the Midlands for June, all courses also come with the chance to win an xbox 360, and Silverlight Spy licences!

Early bird discount of £100 if you book in May, and if you are a member of #SLUGUK or #nxtgenug there are additional discounts to be had.

Full Details are here: http://silverlightmasterclass.net

In addition bbits are holding a raffle for a free ticket for the masterclass. To be eligible to win the ticket (worth £1095!) you MUST paste this text, including all links, into your blog and email Ian@bbits.co.uk with the url to the blog entry.  The draw will be made on June 1st and the winner informed by email and on http://silverlightmasterclass.net

Bindings Not Updating in WPF / Silverlight? Common Mistakes

Introduction

Yesterday I was working on a small prototype, which I will be blogging about shortly, and ran across the common problem of my bindings not updating. A very common problem, and one that’s usually a very simple fix once you’ve tracked it down.

Yes, I’m an Idiot!

Normally my ViewModels inherit from my ViewModelBase base class, which provides a RaisePropertyChanged method and, when in debug mode, uses reflection to check if the property name is valid. Now I’d recently refactored the code so this particular ViewModel wasn’t using the base class, so my first instinct was that I’d simply mistyped the property name magic string in the event – but that was all fine.

I threw in a few breakpoints and I could see my ViewModel was changing, I could see the OnPropertyChanged method being hit, but there didn’t seem to be any listeners and as a result my UI was just ignoring the changes.

After a few minutes of head scratching I noticed that although my class was firing the PropertyChanged event correctly, I hadn’t added INotifyPropertyChanged to my class declaration when I removed the base class! So although I was firing an event that looked like INotifyPropertyChanged.PropertyChanged, I was actually just firing my own event with the same name 🙂

Conclusion

So there you have it, I’m an idiot 🙂 The moral of the story is, when your bindings aren’t working check the obvious:

  1. The property name is correct. A base class that checks this in debug mode can be useful, or failing that, watch the Output window.
  2. Check you are actually implementing INotifyPropertyChanged and not just firing events that happen to have the same name 🙂

Why Shouldn’t I use PRISM?

Introduction

PRISM, or Composite Application Guidance/Library for WPF/Silverlight, is a library and a corresponding guidance document that helps you to build loosely coupled “composite” WPF and Silverlight applications.

The library itself “sits on top” of an Inversion of Control Container (Unity by default), and provides facilities for modularising your application, composing your UI from components, loosely coupling events and, in Silverlight’s case, only downloading parts of your application as and when they’re required.

Sounds great doesn’t it?

So, There Must Be Something Wrong With It.. Right?

Plenty has been written about PRISM, its benefits, and how to get started; but very little on why you wouldn’t use it on your next WPF/Silverlight project. I’ve put together some concerns, based both on criticisms I’ve read, and supposition on my part; and some commentary about whether I believe those concerns are well founded or not.

“I’m Only Doing a Small Project!”

Granted, PRISM is rather overkill for “toy” applications; but are you sure your application is always going to stay that small and simple? One of the big advantages of the modular nature of a PRISM app is being able to add and test new features with relative ease. I’m sure we’ve all started projects that started off as a simple little toy app, but have since grown organically into something rather more complex – possibly ending up with some pretty kludgey code at the end of it.

“It’s Complicated!”

No; it’s not. Really. There’s nothing particularly complex in PRISM, either conceptually or in the code you have to write. Once you understand the structure of a PRISM project, you’ll probably find that your code is actually easier to follow, as it is separated into clearly defined parts.

If you want an easy to follow tutorial that takes you from File.. New, through to a working application, then take a look at the excellent screencasts from Blaine Wastell’s blog.

“It Takes Too Long To Use! There’s Too Much Overhead!”

If you’ve watched some of the initial screencasts about PRISM, or had a peak at some sample code, you might be thinking that the overhead of creating all these “extra” classes and projects is just too much. While it certainly is more work than just File.. New and throwing controls on a page; once your initial project structure and bootstrapper is setup, adding new modules is no more time consuming than adding a normal User Control.

Separating your view from it’s logic; whether it be with ViewModels, the Presentation Model, or any other pattern, is going to be slightly more work; but the testability and data binding benefits far outweigh any slight increase in typing!

“It Will Add Bloat to My Silverlight App!”

The PRISM binaries, including Unity, weigh in at around 270k; and squeeze down to approximately 100k when zipped. Not exactly tiny, but not exactly Bloaty McBloater. In fact, if you take advantage of PRISM’s ability to bundle parts of your Silverlight application into different XAP files, and only load them when needed, you may find your initial payload is actually smaller than it would be without PRISM.

“You Have To Use Unity! I Don’t Want That Dependency!”

I’ve seen this repeated several times, but it’s simply not true. Although PRISM “out of the box” uses Unity, and comes with a Unity Bootstrapper; you can plug in your own IoC container without too much trouble. At the time of writing I believe there are alternatives for Spring.Net, Castle Windsor and StructureMap already written for you.

“I Want Control Over *ALL* My Damn Code!”

Firstly, if you’re writing a .Net application then chances are you are calling at least one library that you didn’t write 🙂 Secondly, PRISM is very “lightweight”. It’s a helping hand at your disposal, rather than a monolithic framework that takes over your whole application and forces you to work in a certain way. Thirdly, you can just pick and choose which parts of PRISM you want to use, it’s not an “all or nothing” proposition. Don’t like the view composition? Then don’t use it! And finally, it’s all open source, so if you don’t like the way something works – change it! 🙂

“It’s From MS – So It Sucks!”

Unfortunately if someone holds this view, then there’s probably nothing anyone can say to change their mind. While everything that comes out of Microsoft isn’t perfect, far from it, it most certainly doesn’t all suck 🙂

With PRISM, the exceedingly smart guys from the Patterns and Practices team have created an excellent set of tools and guidance to help solve some very common problems; without producing a heavy, complicated framework in the process (CAB anyone? 🙂 )

“I Can’t Frikkin’ Find It!”

Ok, I admit it, you’ve got me on this one! 🙂 Is it on MSDN? Is it on CodePlex? Both?! Is it called PRISM? The Composite Application Library (CAL)? Or maybe Composite Application Guidance for WPF and Silverlight (CAG)?

Now CAL obviously refers to the library, CAG to the guidance, and I believe PRISM is an umbrella term for the whole project, but the naming is certainly confusing, and searching for PRISM takes you to CodePlex then MSDN and back again, so it’s very easy to get confused! In fact, finding, downloading and building the library is actually MORE confusing than using the damn thing! There is actually a whole article on Sparking Client on How to Find, Download and Build Prism for Silverlight, which speaks volumes 🙂

I really don’t see what’s wrong with calling the whole thing PRISM and leaving it at that. If I say  “.Net Framework”, then most developers would know what I mean. There’s certainly no need for me to call it the “Microsoft Framework for Building Managed Applications Targeting the Windows Platform (MFBMATWP)” 😉

Tell Me More!

If you want to know more about PRISM, or if you want some walkthroughs and examples of how to use it, then here’s some links that should float your boat: