TreeView Item model and ItemsSource

In order to bind something to a control in UWP, you need something. Essentially, what that means is that we need a model.

A model, in .NET terms, is simply a class that holds data.

We're going to create a new class, and we'll call it Item:

public class Item
{
    public string Name { get; set; }
    public ObservableCollection<Item> Children { get; set; } = new ObservableCollection<Item>();
    public ItemType ItemType { get; set; }
    public string FullName { get; set; }
 
    public override string ToString()
    {
        return Name;
    }
}
I would always recommend that models are held in their own file and sit in a folder called Models, but there's no technical reason why you couldn't add this class to the end of ImportBooks.cs.

Most ...

Get C# 8 and .NET Core 3 Projects Using Azure - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.