Esempio n. 1
0
        /// <summary>
        /// 根据指定值获取节点
        /// </summary>
        /// <param name="list"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private CascaderNode GetNodeByValue(List <CascaderNode> list, string value)
        {
            if (list == null)
            {
                return(null);
            }
            CascaderNode result = null;

            foreach (var node in list)
            {
                if (node.Value == value)
                {
                    return(node);
                }

                if (node.HasChildren)
                {
                    var nd = GetNodeByValue(node.Children.ToList(), value);
                    if (nd != null)
                    {
                        result = nd;
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 选中节点
        /// </summary>
        /// <param name="cascaderNode"></param>
        /// <param name="selectedType"></param>
        internal void SetSelectedNode(CascaderNode cascaderNode, SelectedTypeEnum selectedType)
        {
            if (cascaderNode == null)
            {
                return;
            }

            SelectedType = selectedType;
            if (selectedType == SelectedTypeEnum.Click)
            {
                _selectedNodes.Clear();
                SetSelectedNodeWithParent(cascaderNode, ref _selectedNodes);
                _renderNodes = _selectedNodes;

                if (ChangeOnSelect || !cascaderNode.HasChildren)
                {
                    SetValue(cascaderNode.Value);
                }
            }
            else
            {
                _hoverSelectedNodes.Clear();
                SetSelectedNodeWithParent(cascaderNode, ref _hoverSelectedNodes);
                _renderNodes = _hoverSelectedNodes;
            }
            _renderNodes.Sort((x, y) => x.Level.CompareTo(y.Level));  //Level 升序排序

            if (!cascaderNode.HasChildren)
            {
                ToggleState  = false;
                IsOnCascader = false;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 下拉节点单击
        /// </summary>
        /// <param name="node"></param>
        private void NodeOnClick(CascaderNode node)
        {
            if (node.Disabled)
            {
                return;
            }

            SetSelectedNode(node, SelectedTypeEnum.Click);
        }
Esempio n. 4
0
        /// <summary>
        /// 设置选中所有父节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="list"></param>
        private void SetSelectedNodeWithParent(CascaderNode node, ref List <CascaderNode> list)
        {
            if (node == null)
            {
                return;
            }

            list.Add(node);
            SetSelectedNodeWithParent(node.ParentNode, ref list);
        }
Esempio n. 5
0
        /// <summary>
        /// 初始化节点属性(Level, ParentNode)
        /// </summary>
        /// <param name="list"></param>
        /// <param name="parentNode"></param>
        /// <param name="level"></param>
        private void InitCascaderNodeState(List <CascaderNode> list, CascaderNode parentNode, int level)
        {
            if (list == null)
            {
                return;
            }

            foreach (var node in list)
            {
                node.Level      = level;
                node.ParentNode = parentNode;

                if (node.HasChildren)
                {
                    InitCascaderNodeState(node.Children.ToList(), node, level + 1);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 下拉节点移入
        /// </summary>
        /// <param name="node"></param>
        private void NodeOnMouseOver(CascaderNode node)
        {
            if (ExpandTrigger != "hover")
            {
                return;
            }

            if (node.Disabled)
            {
                return;
            }
            if (!node.HasChildren)
            {
                return;
            }

            SetSelectedNode(node, SelectedTypeEnum.Hover);
        }