I have a hierarchy of data that looks like this:
- Policy
- Check
- Action
- Action
- Action
- Check
- Action
- Check
- 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,开发者_如何学Python especially with a hierarchy of data model objects).
What is the best known way to do this?
This looks more like a TreeView
than a StackPanel
to me.
In MVVM you bind to the hierarchy and define HierarchicalDataTemplate
s for each node type.
Have a look at this question: Having HierarchicalDataTemplates in a TreeView
精彩评论