" can be read ...">

WPF design question involving treeview

I have a hierarchy that looks like this: Factory> Machines> Components> Controls, where ">" can be read as "contains a list".

This fits very well into a TreeView using HierarchicalDataTemplates. Now say that I want to add checkboxes to the tree so that the user can create tree "views" that need control. Currently my templates are data bound to real machine / component / control objects like ...

<HierarchicalDataTemplate DataType="{x:Type src:Component}" ItemsSource = "{Binding Path=Controls}">
    <StackPanel Orientation="Horizontal">
        <CheckBox IsChecked="False" />
        <TextBlock Text="{Binding Path=Name}"/>
    </StackPanel>
</HierarchicalDataTemplate>

      

I don't want to change the code of my machines / components / control classes to be able to handle the creation of a "view". In other words, I want to keep the "data model" code and the user interface code separate. For example, to process this checkbox, I need to bind it to the IsSelected property of the control. I found myself adding a bunch of properties and notification code for these classes. Another alternative that I have tried is to create a "view" class for each machine / component / control class. With this approach, I ended up making copies of the data in the view classes and had to sync them up with the actual data. What's a good way to do this?

0


source to share


1 answer


These two CodeProject articles helped me:



+2


source







All Articles