简体   繁体   中英

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...

您必须使用hierarhical数据模板

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM