Example #1
0
        public DepartmentViewModel(Department department, DepartmentViewModel parent)
        {
            _department = department;
            _parent = parent;

            _children = new ObservableCollection<DepartmentViewModel>(
                    (from child in _department.Children
                     select new DepartmentViewModel(child, this))
                     .ToList<DepartmentViewModel>());
        }
        public DepartmentTreeViewModel(Department rootDepartment)
        {
            _rootDepartment = new DepartmentViewModel(rootDepartment);

            _firstGeneration = new ObservableCollection<DepartmentViewModel>(
                new DepartmentViewModel[] 
                { 
                    _rootDepartment
                });

            //_firstGeneration.CollectionChanged += _firstGeneration_CollectionChanged;

            _searchCommand = new SearchFamilyTreeCommand(this);
        }
        IEnumerable<DepartmentViewModel> FindMatches(string searchText, DepartmentViewModel person)
        {
            if (person.NameContainsText(searchText))
                yield return person;

            foreach (DepartmentViewModel child in person.Children)
                foreach (DepartmentViewModel match in this.FindMatches(searchText, child))
                    yield return match;
        }