Example #1
0
        public TreeViewModel()
        {
            _RootTreeNode = new TreeNodeModel("根节点");


            TreeNodeModel hunan = new TreeNodeModel("湖南", _RootTreeNode);


            TreeNodeModel hubei = new TreeNodeModel("湖北", _RootTreeNode);


            TreeNodeModel shaoyan = new TreeNodeModel("邵阳", hunan);
            TreeNodeModel hengyan = new TreeNodeModel("衡阳", hunan);
            TreeNodeModel wuhan   = new TreeNodeModel("武汉", hubei);

            _RootTreeNode.Children.Add(hubei);
            _RootTreeNode.Children.Add(hunan);
            hunan.Children.Add(shaoyan);
            hunan.Children.Add(hengyan);
            hubei.Children.Add(wuhan);

            _FirstGeneration = new ObservableCollection <TreeNodeModel>(new TreeNodeModel[] {
                _RootTreeNode
            });
        }
        public TreeNodeModel createChild(string id, string name)
        {
            var node = new TreeNodeModel(id, name, this);

            Children.Add(node);
            return(node);
        }
        public TreeNodeModel(string id, string text, TreeNodeModel parent)
        {
            _Id     = id;
            _Text   = text;
            _Parent = parent;

            _Children = new ObservableCollection <TreeNodeModel>(new TreeNodeModel[] { });
        }
Example #4
0
        IEnumerable <TreeNodeModel> FindMatches(string searchText, TreeNodeModel treeNode)
        {
            if (treeNode.TextContainsText(searchText))
            {
                yield return(treeNode);
            }

            foreach (TreeNodeModel child in treeNode.Children)
            {
                foreach (TreeNodeModel match in this.FindMatches(searchText, child))
                {
                    yield return(match);
                }
            }
        }
Example #5
0
 TreeNodeModel FindSelected(TreeNodeModel treeNode)
 {
     if (treeNode.Selected)
     {
         return(treeNode);
     }
     foreach (TreeNodeModel child in treeNode.Children)
     {
         if (child.Selected)
         {
             return(child);
         }
     }
     return(null);
 }
 public TreeNodeModel(string text, TreeNodeModel parent)
     : this(null, text, parent)
 {
 }
Example #7
0
 public void SelectedItemChanged(TreeNodeModel node)
 {
     MessageBox.Show("hello " + node.Text);
 }