Marcin Petrów
Marcin Petrów

Reputation: 1497

TreeView data binding in C#/WPF

Can someone help me understand way fo creating xaml code for TreeView component and model like this one:

class Task: ObservableObject
{
    private string _title;

    public string Title {
        get { return _title; }
        set { 
            if (value != _title) {
                _title = value;
                OnPropertyChanged("Title");
            } 
        }
    }

    public override string ToString() {
        return Title;
    }
}

class Tasks:ObservableCollection<Task>
{

}

class Group:ObservableObject
{
    private Tasks _tasksList;

    public Group() {
        _tasksList = new Tasks();
    }

    public Tasks TasksList {
        get{
            return _tasksList;
        }

        set {
            if (value != _tasksList) {
                _tasksList = value;
                OnPropertyChanged("TasksList");
            }
        }
    }
}

class Groups:ObservableCollection<Group>
{

}

All I want to have is View with TreeView component and data like

Group1
   Task 1
   Task 2
Group2
   Task 3
   Task 4

using a InputSource and DataContext...

Upvotes: 0

Views: 5019

Answers (1)

m0sa
m0sa

Reputation: 10950

You have to use hierarhical data templates.

Upvotes: 2

Related Questions