Example #1
0
        public TreeNodeVm(TreeNodeVm parentNodeVm, object item, IExpandedProvider expanded = null)
        {
            Item      = item;
            Id        = (GetItemProperty("Id") as string) ?? Guid.NewGuid().ToString("N");
            _expanded = expanded;
            Parent    = parentNodeVm;
            Children  = new List <TreeNodeVm>();

            IsExpanded  = _expanded?.GetExpanded(Id) ?? false;
            IsDraggable = parentNodeVm != null;

            Name = GetItemProperty("Name") as string;
            Icon = GetItemProperty("Icon") as string;

            CreateChildCfgNodes();
        }
Example #2
0
        // ReSharper disable once UnusedMember.Global
        public void TreeSelect(string nodeId)
        {
            var node = _rootNode.FindNodeById(nodeId);

            if (node == null)
            {
                return;
            }

            foreach (var treeNode in _rootNode.AllNodes())
            {
                treeNode.IsSelected = false;
            }
            node.IsSelected = true;
            SelectedNode    = node;
            SelectionChanged();
        }
Example #3
0
        protected void SetRootNode(object item, bool showRootNode = true, bool expandRootNodes = false)
        {
            _rootNode = new TreeNodeVm(null, item);
            RootNodes = showRootNode
                ? new List <TreeNodeVm> {
                _rootNode
            }
                : _rootNode.Children;

            if (!expandRootNodes)
            {
                return;
            }

            foreach (var node in RootNodes)
            {
                node.IsExpanded = true;
            }
        }
Example #4
0
        private void CreateChildCfgNodes()
        {
            if (!(GetItemProperty("Children") is IEnumerable <object> children))
            {
                return;
            }

            if (Children.Any())
            {
                return;
            }

            foreach (var child in children)
            {
                var childNode = new TreeNodeVm(this, child, _expanded);
                childNode.CreateChildCfgNodes();
                Children.Add(childNode);
            }
        }