예제 #1
0
        protected override async Task OnParametersSetAsync()
        {
            if (_rootNodes == null)
            {
                throw new ArgumentException($"One of the following must be supplied {nameof(RootNode)} or {nameof(RootNodes)} (but NOT BOTH)");
            }
            if (NodeTemplate == null)
            {
                throw new ArgumentException($"The parameter {nameof(NodeTemplate)} has not been set");
            }
            if (GetChildNodesCallback == null)
            {
                throw new ArgumentException($"The parameter {nameof(GetChildNodesCallback)} has not been set");
            }

            // ensure everything is expanded up to the selected node
            List <TNode> pathToSelected = new List <TNode>();

            BuildPathToSelected(this.RootNodes, pathToSelected);
            //if (pathToSelected.Count > 0) pathToSelected.RemoveAt(0); // don't expand the selected node
            foreach (TNode pathNode in pathToSelected)
            {
                if (this.IsNodeExpanded(pathNode) == false)
                {
                    this.ExpandedNodes.Add(pathNode);
                    await ExpandedNodesChanged.InvokeAsync(new ExpandedNodesChangedArgs <TNode>(this.ExpandedNodes, pathNode, true));
                }
            }

            await base.OnParametersSetAsync();
        }
예제 #2
0
        private void OnToggleNode(TNode node, bool expand)
        {
            bool expanded = ExpandedNodes.Contains(node);

            if (expanded && !expand)
            {
                ExpandedNodes.Remove(node);
                ExpandedNodesChanged.InvokeAsync(ExpandedNodes);
            }
            else if (!expanded && expand)
            {
                ExpandedNodes.Add(node);
                ExpandedNodesChanged.InvokeAsync(ExpandedNodes);
            }
        }
예제 #3
0
        internal async Task SetExpandedNodesAsync(TNode node, bool expanded)
        {
            if (expanded)
            {
                this.ExpandedNodes.Add(node);
            }
            else
            {
                this.ExpandedNodes.Remove(node);
            }

            await ExpandedNodesChanged.InvokeAsync(new ExpandedNodesChangedArgs <TNode>(this.ExpandedNodes, node, expanded));

            await EnsureSelectedNodeIsVisible();

            StateHasChanged();
        }