Sorry to ask just a wide question, but I am having trouble thinking how to approach this problem.
I have a many to many relationship:
Product 1 --- * ProductCategory * --- Category
Category also has:
Category 0..1 --- * Category (As SubCategories)
What I want to to see a tree view, with all categories, and be able to check a checkbox to create the ProductCategory entity. I do not how to approach this with MVVM.
In ASP.NET, when rendering the tree view I would check to see if the CategoryId of the node I was rendering was in my list of 'ProductCategory's if it was, I would check the box, and so setting up the initial state.
Then I would attach event handlers to the nodes (along with maybe some data) so that when the checkbox was checked/unchecked, it would add/remove the appropriate entity from my list.
The problem is I'm trying to move towards MVVM, and sometimes seeing how exactly it helps, and whilst some things a neater, doing anything complicated seems to be a pain! For example, my inital thought was to bind the top level Category (Root) to the tree, and render all entities using the HierarchicalDataTemplate:
<sdk:TreeView Margin="0,3,30,3" ItemsSource="{Binding Categories}" Height="300">
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding SubCategories}">
<StackPanel Orientation="Horizontal">
<CheckBox></CheckBox>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Left"></TextBlock>
</StackPanel>
</sdk:HierarchicalDataTemplate>
<!---->
</sdk:TreeView.ItemTemplate>
The problem is that I cannot bind my checkbox to anything, because Category has no field I can use to attach it to a product...
Please can an MVVM guru throw some light on this, or should I simply go down the 'event' route?
Many Thanks.