I used the solution provided in this answer in order to use two different view models dependent on the type within my composite collection.
An extract of the view is as follows:
<ItemsControl ItemsSource="{Binding DecksAndCards}" >
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type viewModel:DeckViewModel}">
<view:DeckView />
</DataTemplate>
<DataTemplate DataType="{x:Type viewModel:CardViewModel}">
<view:CardView />
</DataTemplate>
</ItemsControl.Resources>
...
The view resides within a View
project referencing only the ViewModel
project until now.
However by using x:Type
(which I think acts as a static reference) I need to add to my view project a reference to my DomainLayer project, because the ViewModel project also references it.
If I don't add this reference I get the error:
Unknown build error, 'Cannot resolve dependency to assembly 'DomainLayer, [...] because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
Following the MVVM pattern the View should not have references to the Model directly. So my question is, is there another solution than the one I posted above or do I need to break the pattern in this case?