开发者

How to use WPF Data Binding with an MVVM Model to Populate a StackPanel with Custom Controls

开发者 https://www.devze.com 2023-04-11 00:57 出处:网络
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 programma

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,开发者_如何学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 HierarchicalDataTemplates for each node type.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消