2

I have a hierarchy of data that looks like this:

  • Policy
    • Check
      • Action
      • Action
      • Action
    • Check
      • Action
    • Check

For each Policy/Check/Action, I have a custom control built in WPF. I have been programmaticly adding new instances of my controls to containers in the parent control. (IE. When a user clicks the "Add Check" in the Policy control, I will do a MyPolicy.StackPanelChecks.Children += new CheckControl() ). I am converting to an MVVM model and am trying to use data binding to populate this StackPanel (and don't want to embed DataTemplates into my code, especially with a hierarchy of data model objects).

What is the best known way to do this?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72

1 Answers1

2

This looks more like a TreeView than a StackPanel to me.

In MVVM you bind to the hierarchy and define HierarchicalDataTemplates for each node type.

Have a look at this question: Having HierarchicalDataTemplates in a TreeView

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115