【问题标题】:hierarchical data template class for treeview树视图的分层数据模板类
【发布时间】:2012-03-14 18:23:25
【问题描述】:

我想在我的项目中为我的树视图实现一个分层数据模板。 结构应该是这样的:

- ManagedItems (RootItem)
     - Department 1
         -Client 1
             - Feature 1
             - Feature 2
         -Client 2
             - Feature 1
     - Department 2
             - Department 4
                     - Department 5
                            -Client 4
                                   - Feature 1
     - Department 3
         -Client 3
             - Feature 1
             - Feature 2
             - Feature 3


//Current class for datatype
public class Entries
{
    public string Department { get; set; }
    public string Client { get; set; }

    // ?? How to implement a drive array and a feature array which will be displayed correctly in the treeview?

    public ObservableCollection<Entries> Children { get; set; }
}

它在 C# 和 WPF (.NET 4.0) 中。 有什么想法吗?

谢谢。

【问题讨论】:

    标签: c# wpf treeview


    【解决方案1】:

    模型的线框:

    class ManagedItems {
       IList<Department> Departments // TreeView.ItemsSource
    }
    class Department {// HierDT
       IList<object> Children // HierDT.ItemsSource; (can either be Department or Client)
    }
    class Client {// HierDT
       IList<Feature> Features // HierDT.ItemsSource
    }
    class Feature { } // normal DataTemplate
    

    TreeView.Resources 中定义DepartmentClient HierDTsFeature DataTemplate

    注意Department.Childrenobjects。这没关系,因为当 WPF“看到”Client 时,它会“膨胀”到适当的 HierDT(以及当它“看到”Department 时,它会膨胀到 Department 的定义HierDT)。

    【讨论】:

    • this article 是 Web 上 WPF TreeView 事实上的最佳示例。如果您还没有听说过 MVVM,您可能还想看看它的一些示例。
    猜你喜欢
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 2020-07-09
    • 1970-01-01
    • 2017-02-03
    • 2012-11-05
    相关资源
    最近更新 更多