I have a View with several DataTemplate
s. Each DataTemplate
has a View and ViewModel like so:
<DataTemplate DataType="{x:Type viewModels:exampleViewModel}">
<AdornerDecorator>
<ScrollViewer>
<views:exampleView />
</ScrollViewer>
</AdornerDecorator>
</DataTemplate>
Then I have a TabControl
which is bound to a DataContext
.
In the DataContext, there is a Collection which has a list of all the different viewModels referenced by the DataTemplates:
<TabControl
DataContext="{Binding}"
ItemsSource="{Binding Collection, Mode=OneWay}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding}" />
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
Obviously there is one 'main' ViewModel for the View that contains the TabControl.
This works pretty well, creating TabItem
s for me for each item in the Collection and also setting the content of each page.
I now want to move this over to Catel but have no idea on where to begin because (and correct me if I'm wrong) :
I now should not have any reference to any other ViewModel within any ViewModel and
Catel automatically will link up my Views and ViewModels for me.
Any suggestions?
Collection
property holds all of your view models, then that means that they are all instantiated and using up resources even when they are not being displayed. I'd use the move to Catel to rework your design if I were you. – Sheridan