public class TaskViewModel : INotifyPropertyChanged { private Task vmTask; private ObservableCollection<TaskViewModel> vmSubTasks; TaskViewModel vmParent; bool vmIsExpanded; bool vmIsSelected; public bool VmIsVisited { get; set; } //ctors public TaskViewModel(Task task, TaskViewModel prnt) { VmTask = task; //:Me vmTask = task; Parent = prnt; //:Me vmParent = parent; ///<summary> ///recursively walks down the Task tree, wrapping each Task object in a TaskViewModel ///</summary> SubTasks = new ObservableCollection<TaskViewModel>( //:Me vmSubTasks = new ObservableCollection<TaskViewModel>( (from t in vmTask.SubTasks select new TaskViewModel(t, this)).ToList<TaskViewModel>()); } public TaskViewModel(Task task) : this(task, null) { } public bool IsExpanded { get { return vmIsExpanded; } set { if (value != vmIsExpanded) { vmIsExpanded = value; this.OnPropertyChanged("IsExpanded"); } // Expand all the way up to the root. if (vmIsExpanded && vmParent != null) Parent.IsExpanded = true; //fantastic! (executes the setter again) } } public bool IsSelected { get { return vmIsSelected; } set { if (value != vmIsSelected) { vmIsSelected = value; this.OnPropertyChanged("IsSelected"); OnPropertyChanged("Name"); //required: reflects the change of txtName to the corresponding TreeViewItem name //OnPropertyChanged is only required for the Name property } } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)