views:

582

answers:

1

When you use the MVVM Visual Studio Template, then your ViewModels are bound to your Views' DataContexts in the App.xaml.cs something like this:

MainView mainView = new MainView();
mainView.DataContext = new MainViewModel();
mainView.Show();

And if you use Composite Application Library, then you have your Views and ViewModels being bound together in your Bootstrapper/Container/ServerLocator, etc.

In any case, when you open these projects in Expression Blend and open a View XAML file, Expression blend doesn't know which ViewModel belongs to which View since this binding is done in code as in above instances.

You can of course set a DataObjectProvider in your XAML so Expression Blend knows where to get its data for that View but this breaks MVVM and the decoupling pattern since your View is now hard-wired to a specific ViewModel. It this how designers normally work with Expression Blend on projects that are more than a little demo?

So for those of you using the MVVM pattern and who have designers who use Expression Blend, how are you keeping your View/ViewModel binding structured so that Expression Blend can know which ViewModel belongs to which Views?

+1  A: 

Blend does load and execute code, even though it doesn't run the application. Load some sample DataContext if DesignerProperties.GetIsInDesignMode(...) in a view constructor or another more appropriate method.

ima