pjdupreez
pjdupreez

Reputation: 717

Collection of ViewModels in Catel

I have a View with several DataTemplates. 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 TabItems 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) :

  1. I now should not have any reference to any other ViewModel within any ViewModel and

  2. Catel automatically will link up my Views and ViewModels for me.

Any suggestions?

Upvotes: 4

Views: 620

Answers (1)

Geert van Horrik
Geert van Horrik

Reputation: 5724

I recommend moving to Catel. It does solve this issue (this is actually why it was written in the first place). For a good starting point, check out the extensive documentation:

https://catelproject.atlassian.net/wiki/display/CTL/Catel+documentation+Home

A good read is the getting started with WPF part:

https://catelproject.atlassian.net/wiki/display/CTL/Getting+started+with+WPF

Also check out the examples repository:

https://github.com/Catel/Catel.Examples

Upvotes: 1

Related Questions