Hello,
In my application, I have one class which is having some complex properties in it. This class i want to bind to a treeview to display some data in Hierarchical order.
Below is the code for model classes which i want to show in a TreeView.
public class Employee { public int ID { get; set; } public Name NameOfEmployee { get; set; } public float Salary { get; set; } public Address HomeAddress { get; set; } public Address OfficeAddress { get; set; } public ObservableCollection<Employee> ReportingEmployees { get; set; } } public class Name { public string FirstName { get; set; } public string LastName { get; set; } } public class Address { public int HouseID { get; set; } public string ApartmentName { get; set; } public string City { get; set; } public int PinCode { get; set; } }
TreeView Output should be as follows:
+Employee (FullName)-ID
+Name
-FirstName
-LastName
-Salary
+HomeAddress
-HouseID
-ApartmentName
-City
-PinCode
+OfficeAddress
-HouseID
-ApartmentName
-City
-PinCode
+EmployeesCollection
+Employee1 (FullName)
-ID
+Name
-FirstName
-LastName
-Salary
+HomeAddress
-HouseID
-ApartmentName
-City
-PinCode
+OfficeAddress
-HouseID
-ApartmentName
-City
-PinCode
+Employee2 (FullName)
-ID
+Name
-FirstName
-LastName
-Salary
+HomeAddress
-HouseID
-ApartmentName
-City
-PinCode
+OfficeAddress
-HouseID
-ApartmentName
-City
-PinCode
I tried searching on net but i got examples with only two complex types as properties but didnt found any example where you have to display simple type (int, string, float) and complex type (Address, Employees) together as child nodes.
How i can do this using HierarchicalDataTemplate and binding using XAML?
Thanks in advance,
IamHuM