I'm currently developing a WPF application using the MVVM pattern. The View, Model, ViewModel each are in a seperate Class Library.
My View has a TreeView control which should be filled using databinding.
I get my data from a WCF service which is accessed through the Model. My Model has a service references to the WCF service and calls a method from the WCF to retrieve a nested collection.
The ViewModel makes the data available to the View. Retrieving the data etc all works fine, except for showing it in the TreeView.
My XAML for the TreeView looks like this
<TreeView Grid.Row="1" ItemsSource="{Binding CustomerTree}" >
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type ....}" ItemsSource="{Binding Path=Children}">
<TextBlock Text="{Binding Path=Name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type ....}" ItemsSource="{Binding Path=Children}">
<TextBlock Text="{Binding Path=ID}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
The DataType="{x:Type .....} property expects a certain Type which should be one of the types in my nested collection, but the view does not know which types are available. My ViewModel can access the types the service reference has in the model, for example the customer type by using Model.ServiceReference.Customer.
Is the Model the right place to add a service reference? How should I make my TreeView display the data?
Thanks,
Grant