private async Task selectItemAsync(TItem item, object selected)
        {
            if ((bool)selected)
            {
                SelectedData.Add(item);
            }
            else
            {
                SelectedData.Remove(item);
            }
            await SelectedDataChanged.InvokeAsync(SelectedData);

            StateHasChanged();
        }
        private async Task selectItemsAsync(List <TItem> items, object selected)
        {
            foreach (var item in items)
            {
                if ((bool)selected)
                {
                    if (!SelectedData.Contains(item))
                    {
                        SelectedData.Add(item);
                    }
                }
                else
                {
                    SelectedData.Remove(item);
                }
            }
            await SelectedDataChanged.InvokeAsync(SelectedData);

            StateHasChanged();
        }
Exemple #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);
            }
        }
Exemple #4
0
 /// <summary>
 /// 触发数据选择事件
 /// </summary>
 /// <param name="data"></param>
 protected void OnSelectedDataChanged(object data)
 {
     SelectedDataChanged?.Invoke(data);
 }
Exemple #5
0
 private void OnSelectedDataChanged()
 {
     SelectedDataChanged?.Invoke(this, EventArgs.Empty);
 }
 protected virtual void OnSelectedDataChanged(T e)
 {
     SelectedDataChanged?.Invoke(this, e);
 }