views:

337

answers:

5

I've been doing WPF applications with the MVVM pattern using Visual Studio, coding C# and XAML mostly by hand.

Now I've gotten up to speed with Expression Blend so that I can click together WPF applications quickly just using the GUI, which is very nice, much more control of the layout than fiddling around with all the XAML elements 80% of your time.

But it seems that my applications in Expression Blend are simpler and necessarily coupled, using events that are handled in the code behind, etc.

I find it hard to imagine how I would go from this simpler approach of Expression Blend to a decoupled MVVM application with Views, ViewModels, routed events and commands, etc. other than to just take my whole project into Visual Studio and rearrange it to the point that I couldn't really edit it visually anymore in Blend, but would be back to using Blend to create little pieces of XAML that I paste into Visual Studio.

For those of you who are working with more complex applications with Expression Blend, what are your strategies for keeping your projects decoupled in an MVVM way, yet at the same time structured "in the Expression Blend way" (where you can still see and edit whole parts of your application in a way that makes sense visually) so that you can continue to edit them in the Blend GUI as they scale?

+5  A: 

I've been using Blend first and foremost as a rapid-prototyping tool. For this purpose, I really like it. In particular, I find it very helpful when I'm not sure how to set things up to get the layout/behavior that I want.

I rarely edit my main project files directly in Blend. I find it creates markup that is unnecessarily complex or verbose. Also, as I become more familiar with WPF/XAML, I find myself using Blend less and less.

Daniel Pratt
+1 for the second paragraph.
Bryan Anderson
have you tried Blend 3? I find that its XAML is quite readable, sometimes an extra attribute here and there, but the worst it does is jack the margin on some control up to 500+ or so, but other than that, I really enjoy having my Views editable in Blend so I can change the properties in the GUI, especially with the property search feature, it is almost always faster in Blend
Edward Tanguay
@Edward: If it's beta and it's from Microsoft, safe bet that I've tried it ;-) I actually like Blend quite a bit. It's slick and for some tasks it's almost invaluable.The thing is...day to day XAML for me is layout, and generally I find that, for layout, less is more. I find that I have to do more work in Blend, removing all the extraneous property assignments, to get the behavior/layout I want. Also, when doing a purely data-driven layout, it can be difficult to see or change the layout in the designer.
Daniel Pratt
+2  A: 

I have not been able to successfully use Blend end to end for that.

I find in the general case, it's faster to edit xaml by hand in VS (exception would include anything with non-standard brushes for example). Blend is very click-happy, and it's not really fast to top it off.

Another area where Blend is really useful is creating styles/templates from existing controls.

Other than that, I'm not sold yet. Its capabilities drop when using code-instantiated datacontexts so it's no help there, and it tends to generate useless markup, static sizes and such, which I really don't like.

Denis Troller
+2  A: 

Blend is great for giving you an idea about how things can be done, but the xaml it makes is terrible and tightly coupled. As you learn the xaml side of things better you'll find it's much faster to just write the xaml than use Blend. Until you get to that point you can make your changes in Blend but then you should refactor the xaml it creates to make it less tightly coupled and take out the extraneous UI elements.

Bryan Anderson
+3  A: 

I have been using Blend for the UI of my projects since version 1. Being that my goal is to fully integrate the designer to the project, I have plowed through whatever gets in the way of this goal. While not being aware of MVVM for some time now, I naturally arrived at the same conclusion, and have been making ViewModels without knowing there was a pattern for them. Now with the help of others that are working towards MVVM, it's getting better all the time. I have now developed 3 applications with rich UI and functionality where all the UI was done in Blend. Read Josh Smith's MSDN article, look at Jason Dolinger's work, and Karl Shifflett's work to mention just a few.

Look closely at using ICommand, INotifyPropertyChanged, the ObservableCollections.

Also, look for how you can manipulate controls from your ViewModel. As an example, there is ICollectionView. Assume that you have a list of animals, and you have a set of types that you want to filter them by (birds, mammals, etc.)

By using ICommand and ICollectionView, you could expose enough control where a designer could construct a listbox to show the animals, and a menu to show the filter list. There is enough functionality in ICollectionView to know what the current selection is, and if you had ICommand-based commands for "SortByBird", "SortByMammal", etc then when the designer made the menu, it (assuming the window's context was your ViewModel for this window) would supply the designer with the proper options to bind to.

I am currently working with another team at my company explaining how my projects have been set up, and they are responding positively to the new role of the designer using Blend.

Edward Tanguay
A: 

I'm a little late to this party, but hope that someone can still respond. I've yet to find a search result that outlines the process for drawing a line between the designer and programmer. The first part of it is MVVM so there isn't any coupling between the GUI and the underlying "business logic", and I'm working hard on learning that right now. The other part that I haven't seen anyone write about is, how do you actually go about designing a project in Blend so that the developer can basically give you a GUI DLL of sorts, and then your application's GUI magically changes?

Here's what I'm looking for -- the developer writes his code as usual, and also writes a very basic GUI that proves everything works as expected. Meanwhile, the designer is creating his cool little GUI with all of the usability features people have come to expect. Now, the developer can run his application with his GUI, but then can also switch to the designer's GUI on the fly.

I guess if it can't be done on the fly, does that mean in the ideal case that the developer would have his VS solution include the XAML from the Blend solution? Then in App.xaml just reference a different start file?

Dave
I also didn't mention the importance of testability, but I think this topic has been well-covered in several posts.
Dave