I have a collection that holds multiple types of items that all inherit from the same interface. This is bound to an ItemsControl. The DataContext of the window is set to the ViewModel that holds the collection.
What I would like to do is have each item of a different type in the collection use a different ViewModel.
So if my templates in the itemscontrol are setup like below I would like to have the first template have a DataContext of ViewModel1 and the second have a DataContext of ViewModel2. I can't set the DataContext directly on them because the ItemsControl will set the DataContext to the item.
Anyone know a solution to this, or a better way to do it using MVVM?
<DataTemplate DataType="{x:Type Models:ItemType1}">
<Controls:MyControl Text="{Binding Body}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type Models:ItemType2}">
<Controls:MyControl2 Text="{Binding Body}"/>
</DataTemplate>