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