This is a collection of EmployeeType objects. The last class you create is a collection class called EmployeeTypes created using the generic List class. First is a string property, called Description, which holds the name of the EmployeeType, such as “Supervisor” or “Project Manager.” The second property, Employees, is a generic collection property to hold a list of Employee objects that are associated with this particular EmployeeType. The EmployeeType class contains two properties. A constructor is created to accept a name argument that you can use to set the Name property when you create an Employee object. This class has a single property called Name. The first class you build is the Employee class. Just as a TreeView is a hierarchical structure, create a set of classes that is also a hierarchy.įigure 2 shows the three classes that will be necessary for expressing a hierarchy of EmployeeType objects of which each EmployeeType object can hold one or more Employee objects.įigure 2: Three classes are needed to express a three-level TreeView. What's important is how you structure the classes into which your data will be placed. How and from where you retrieve the data is not important for this article. You want to retrieve data from a database table or an XML file and build the TreeView dynamically. You don't want to use hard-coded XAML in your WPF application. įigure 1 shows you how this TreeView looks when you run the WPF application.įigure 1: A hard-coded two-level TreeView Create Hierarchical Classes to Mimic Your TreeView To start, let's look at the typical two-level WPF TreeView that has been hard-coded with the values shown in the following code snippet. In this article, I'm going to break down how these templates work, so you can really understand what's going on underneath the hood. What if you have more than two levels? This is where it's vital to understand exactly how the HierarchicalDataTemplates work. There are many examples of using the Windows Presentation Foundataion (WPF) TreeView that you can find on the Web, however, most of them only show you how to go to two levels.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |