1
votes

I'm currently using MVVM in a WPF project, all works very well. I have one Master view and many Detail views that I manage using a currentView property in my MasterViewModel. By using a datatemplate, I bind a view to a viewmodel. In fact, my master view has a contentcontrol whose content property is binded to my CurrentView property. When I set this currentview property to a viewmodel or another, it calls the corresponding template.

My problem is that using this, my detail views doesn't have explicit datacontext because it is placed by my datatemplate. So in blend, when I open my view to edit its design, I have no datas to bind to my view. If I set a datacontext to my detailview, in blend I can see all datas I can bind but in runtime, the datacontext set by datatemplate is overrided by the datacontext set in my detailview, so I have no datas during runtime.

Does anyone knows how I can create a good MVVM project, with views managed by datatemplates and with datacontext that we can see with Blend ?

Thanks,

2
Hi Steeve. Do you have any code to share? - Ray Booysen
Other questions, Why does your viewmodel bind to a view? It should be the opposite, viewmodels bind to Views. - Ray Booysen
Hi Ray, In fact, I'm using the same principle that you can see here : codeproject.com/KB/WPF/InternationalizedWizard.aspx You have a master viewmodel that have a currentView property (as object).You have two detail viewmodels (let's name theim VMdetail1 and VMdetail2).In my master view, - Steeve
I have a contentControler whose source is binded to MasterViewModel.CurrentView property. In my xaml resources I have datatemplates like this : <DataTemplate DataType="{x:Type local:DetailViewModel1}"> <local:DetailView1 /> </DataTemplate> And in my views I have no datacontext - Steeve
DetailViews datacontexts are set by datatemplate at runtime. When you change the currentview to viewmodel1, it loads the corresponding view with datatemplate. My problem is with blend you can't see datas to bind in your detailview because there is no datacontext. If I add a datacontext in my - Steeve

2 Answers

2
votes

I've got a blog post on this issue: http://www.robfe.com/2009/08/design-time-data-in-expression-blend-3/

My post is all about showing data in blend without having to have that data displayed or even created at runtime.