Is Blend a better WPF designer for developers than Visual Studio?

For ages now I’ve had some XAML that consistently generates error messages in the Visual Studio designer. I’ve found this most frustrating because I was never sure quite what was wrong with the XAML. Compiling and running the application and it worked exactly how it was intended. But the designer simply refused to display it – instead giving this standard message.

Cider Invalid XAML Message 

In the Error List I find:

Cider Invalid XAML Error

Huh? Sure indexes “Must be non-negative and less than the size of the collection.” that makes sense. But which index? Line ‘1’ Position ‘616’ simply refers to the DataTemplate definition – but the whole template is considered “in error”.

The application runs and renders perfectly. It only happens with DataTemplates and I get squiggly lines on the entire DataTemplate so tracking down the exact cause is difficult. Something to do with data-binding is about as close as I got before deciding that I could live without the preview (since I don’t actually use the designer for editing).

So last night – inspired by some of the latest Mix08 videos up on WindowsClient.NET I decided to download and try the latest Expression Blend 2.5 Preview. This last time I used Blend was a pre release 1.0 Beta – and I have to say this program has come a long way since then. My initial impression on the v2.5 Preview are very positive. It’s got a whole heap of features that I wish the Visual Studio designer included:

  1. Resource Viewer!
  2. Binding Editor
  3. Better XAML validation

Better XAML Validation? Yep – take for instance problem I was having with my DataTemplates. Loading this UserControl into Blend I was disappointed to find that it also didn’t render. But lo-and-behold it included errors messages indicating its dislike of my method of binding. Must nicer than the “Index was out of range” error reported by Visual Studio for the same control XAML. Instead for each Binding in the DataTemplate I got the following error:

“The property “Path” is set multiple times.”

Ok – so still not great – but at least it had identified each line within the template that it didn’t like and let me know it was something to do with the data-binding. Now as it turns out I had coded the Bindings as:

<TextBlock Text="{Binding TemplateBinding, Path=Name}" .../>

Why am I using TemplateBinding within a DataTemplate? I dunno – seemed to make sense when I did it and given that it ran without complaint the first time I never blinked an eye – just kept on doing it. So taking out the TemplateBinding my Binding is just…

<TextBlock Text="{Binding Path=Name}" .../>

and hey-presto Blend renders my UserControl without a glitch. Beautiful!

Thinking that at last I had solved the mystery of my missing XAML previews in Cider I flicked back to Visual Studio sharing the same project and re-opened the UserControl. Nope – same error. Recompiled the project – nope same error. Bummer . So its something that doesn’t generate errors at run-time, is not a problem with Blend, but which causes the Visual Studio designer to barf?

So ignoring issues around availability/pricing should developers be using Blend in preference to Visual Studio for authoring XAML? Or is Dev10 going to address the shortfall of Cider vs. Blend. I can understand that Blend is geared for UX designers and as such the two products have different end-users in mind but surely Resources and Binding is something a developer needs to be able to manage effectively?