DataContext for DataTemplates

May 28, 2010 at 8:14 AM
Hi Marlon, I'm currently using MEFedMVVM in a project and must say that I am absolutely loving it. Great job! 2 things that come to mind as "nice to have" features are: 1) A VS template for creating a vm. After creating my tenth vm in the last 2 days I find I'm doing a lot of repeat coding just to get the basic stuff in there and even thought about building a template myself to save time. 2) You might already have this but I hadn't discovered a way yet... a way to pass an object into the vm from xaml. Imagine: <ListBox> <ListBox.ItemTemplate> <DataTemplate> <view:MyView ViewModelParam="{Binding}" /> I'm not sure what the best way would be to support this would be but one kind of "hacky" way I came up with was to set the tag property of the view in xaml and create a ContextAware service that pulls the object from it. The vm then gets ahold of that service and snags the object. Maybe there is already a better way to do this through the framework but if not, I thought I'd pass along what I'm up to in case it sparked some new ideas. Maybe via an attached prop? <view:MyView meffed:ViewModelLocator.Param="{Binding}" /> And then the BaseViewModel class would have a property that would get set. Just thinking out-load. Keep up the great work and thanks for building such an awesome framework!
May 28, 2010 at 8:18 AM
With regards to the VS ProjectTemplate (and Item Template) its coming up soon :) With regards to your example of the Listbox. This is already supported by MEFedMVVM (DataContextAware ViewModels). All you do is pass true in the ExportViewModel like this [ExportViewModel("MyViewModel", true] you can see more here also there is a sample in the samples folder of the source code called DataContextAwareViewModels Hope this helps