private async Task ItemClicked(string key, string value)
        {
            // Apply selected values
            SelectedKey = key;
            Argument    = value;

            // Invoke events
            await SelectedKeyChanged.InvokeAsync(key);

            // Close list div
            CloseList();
        }
Example #2
0
        public void ResetSelection()
        {
            SelectedKeys.Clear();
            SelectedKey = null;

            if (MultiSelect)
            {
                if (SelectedKeysChanged.HasDelegate)
                {
                    SelectedKeysChanged.InvokeAsync(SelectedKeys);
                }
            }
            else
            {
                if (SelectedKeyChanged.HasDelegate)
                {
                    SelectedKeyChanged.InvokeAsync(SelectedKey);
                }
            }
            StateHasChanged();
        }
Example #3
0
        /// <summary>
        /// 更新绑定数据
        /// </summary>
        private void UpdateBindData()
        {
            if (SelectedNodesDictionary.Count == 0)
            {
                SelectedKey   = null;
                SelectedNode  = null;
                SelectedData  = default(TItem);
                SelectedKeys  = Array.Empty <string>();
                SelectedNodes = Array.Empty <TreeNode <TItem> >();
                SelectedDatas = Array.Empty <TItem>();
            }
            else
            {
                var selectedFirst = SelectedNodesDictionary.FirstOrDefault();
                SelectedKey   = selectedFirst.Value?.Key;
                SelectedNode  = selectedFirst.Value;
                SelectedData  = selectedFirst.Value.DataItem;
                SelectedKeys  = SelectedNodesDictionary.Select(x => x.Value.Key).ToArray();
                SelectedNodes = SelectedNodesDictionary.Select(x => x.Value).ToArray();
                SelectedDatas = SelectedNodesDictionary.Select(x => x.Value.DataItem).ToArray();
            }

            if (SelectedKeyChanged.HasDelegate)
            {
                SelectedKeyChanged.InvokeAsync(SelectedKey);
            }
            if (SelectedNodeChanged.HasDelegate)
            {
                SelectedNodeChanged.InvokeAsync(SelectedNode);
            }
            if (SelectedDataChanged.HasDelegate)
            {
                SelectedDataChanged.InvokeAsync(SelectedData);
            }
            if (SelectedKeysChanged.HasDelegate)
            {
                SelectedKeysChanged.InvokeAsync(SelectedKeys);
            }
        }
Example #4
0
        public void RemoveSelection(string key)
        {
            if (MultiSelect)
            {
                if (!SelectedKeys.Contains(key))
                {
                    throw new Exception("This key was not already selected.");
                }

                if (OnChange.HasDelegate)
                {
                    OnChange.InvokeAsync(new BFUDropdownChangeArgs(key, false));
                }

                SelectedKeys.Remove(key);  //this used to be following the next command.  A bug?  I moved it here...

                if (SelectedKeysChanged.HasDelegate)
                {
                    SelectedKeysChanged.InvokeAsync(SelectedKeys);
                }
            }
            else
            {
                if (SelectedKey != null)
                {
                    SelectedKey = null;
                    if (OnChange.HasDelegate)
                    {
                        OnChange.InvokeAsync(new BFUDropdownChangeArgs(key, false));
                    }

                    if (SelectedKeyChanged.HasDelegate)
                    {
                        SelectedKeyChanged.InvokeAsync(SelectedKey);
                    }
                }
            }
            StateHasChanged();
        }
Example #5
0
        public void AddSelection(string key)
        {
            if (MultiSelect)
            {
                if (SelectedKeys.Contains(key))
                {
                    throw new Exception("This key was already selected.");
                }

                if (OnChange.HasDelegate)
                {
                    OnChange.InvokeAsync(new BFUDropdownChangeArgs(key, true));
                }

                SelectedKeys.Add(key);

                if (SelectedKeysChanged.HasDelegate)
                {
                    SelectedKeysChanged.InvokeAsync(SelectedKeys);
                }
            }
            else
            {
                if (SelectedKey != key)
                {
                    SelectedKey = key;
                    if (OnChange.HasDelegate)
                    {
                        OnChange.InvokeAsync(new BFUDropdownChangeArgs(key, true));
                    }
                    if (SelectedKeyChanged.HasDelegate)
                    {
                        SelectedKeyChanged.InvokeAsync(SelectedKey);
                    }
                }
                isOpen = false;
            }
            StateHasChanged();
        }