Wpf treeview observablecollection not updating

01-Dec-2019 18:53

Notice in line 28 of Figure 4 that the Items Source of the Tree View control is using the static resource with the key of the Data as the source of data for the Tree View.With the Items Source property of the Tree View control set to the collection of Employee Type objects, you are now ready to start building the hierarchy of XAML Data Template objects.If you compare Figure 1 and Figure 3, you can see that the two structures are very similar.At the top, you have the employee types (Manager and Project Managers), and the next level under each employee type is a collection of employee objects (Tim, John, David).What’s important here is that the last level displayed in your Tree View is expressed in a is bound to the Name property of your Employee class.

How and from where you retrieve the data is not important for this article.

Listing 2 shows the new code where, after creating an Employee object, you add another employee to the Managed Employees property.

Now that you have your three-level structure built into your classes, you are ready to hook up this three-level structure to your Tree View.

Each Employee object has a Name property that’s used in the Data Template to display the name of the employee in the Tree View.

In the resource, you use a Text Block to display the appropriate Employee Type property in the first level of the Tree View.

How and from where you retrieve the data is not important for this article.

Listing 2 shows the new code where, after creating an Employee object, you add another employee to the Managed Employees property.

Now that you have your three-level structure built into your classes, you are ready to hook up this three-level structure to your Tree View.

Each Employee object has a Name property that’s used in the Data Template to display the name of the employee in the Tree View.

In the resource, you use a Text Block to display the appropriate Employee Type property in the first level of the Tree View.

Now let’s expand upon the two-level Tree View and use three levels in the Tree View.