public void SelectionChanged(SelectionChangedEventArgs args) { lock (SelectedItems) { CollectionExtensions.RemoveAll(SelectedItems, args.RemovedItems.Cast <PickCollectionDataModel>().ToArray()); SelectedItems.AddRange(args.AddedItems.Cast <PickCollectionDataModel>()); } }
/// <summary> /// 点击 Header 选择复选框时触发此方法 /// </summary> /// <param name="state"></param> /// <param name="val"></param> protected virtual async Task OnHeaderCheck(CheckboxState state, TItem val) { switch (state) { case CheckboxState.Checked: // select all SelectedItems.Clear(); SelectedItems.AddRange(Items); // callback await OnSelectedRowsChanged(); StateHasChanged(); break; case CheckboxState.UnChecked: // unselect all SelectedItems.Clear(); // callback await OnSelectedRowsChanged(); StateHasChanged(); break; default: break; } }
/// <summary> /// Notifies that the collection of selected items has changed in the control. Updates the collection of selected items in the view model. /// This method must be invoked by the implementations of the <see cref="BindableSelectedItemsBehavior{T}"/>. /// </summary> /// <param name="addedItems">The list of items that have been added to the selection.</param> /// <param name="removedItems">The list of items that have been removed from the selection.</param> protected void ControlSelectionChanged(IEnumerable addedItems, IList removedItems) { if (BindableSelectedItemsControl.DisableBindings) { return; } if (SelectedItems != null) { updatingCollection = true; if (removedItems != null) { // Optimize removal if most of the selected items are removed if (removedItems.Count > SelectedItems.Count / 2) { var remainingItems = SelectedItems.Where(x => !removedItems.Contains(x)).ToList(); SelectedItems.Clear(); SelectedItems.AddRange(remainingItems); } else { foreach (var removedItem in removedItems.Cast <object>()) { SelectedItems.Remove(removedItem); } } } if (addedItems != null) { SelectedItems.AddRange(addedItems.Cast <object>().Where(x => !SelectedItems.Contains(x))); } updatingCollection = false; } }
/// <summary> /// 点击 Header 选择复选框时触发此方法 /// </summary> /// <param name="state"></param> /// <param name="val"></param> protected virtual Task OnHeaderCheck(CheckboxState state, TItem val) { if (Items != null) { switch (state) { case CheckboxState.Checked: // select all SelectedItems.Clear(); SelectedItems.AddRange(Items); StateHasChanged(); break; case CheckboxState.UnChecked: // unselect all SelectedItems.Clear(); StateHasChanged(); break; default: break; } } return(Task.CompletedTask); }
/// <summary> /// Initializes a new instance of the <see cref="GarnishSelectViewModel"/> class. /// </summary> /// <param name="dialogService">Dialog service dependency.</param> /// <param name="garnishService">Tag service dependency.</param> /// <param name="selectedGarnishes">Loc25 provider dependency.</param> public GarnishSelectViewModel(DialogService dialogService, CRUDService <Recipe> garnishService, IEnumerable <RecipeEdit> selectedGarnishes) : base(dialogService) { AllGarnishes = garnishService.GetMapped <RecipeEdit>(x => x.Tags.Any(t => t.Name == "Гарниры")).OrderBy(x => x.Name).ToList(); SelectedItems.AddRange(AllGarnishes.Intersect(selectedGarnishes)); }
/// <summary> /// 点击 Header 选择复选框时触发此方法 /// </summary> /// <param name="state"></param> /// <param name="val"></param> protected virtual void OnHeaderCheck(CheckboxState state, bool val) { SelectedItems.Clear(); if (state == CheckboxState.Checked && Items != null) { SelectedItems.AddRange(Items); } ItemCheckboxs?.ForEach(checkbox => checkbox.SetState(state)); }
private async Task InvertSelect() { var items = Items.Where(i => !SelectedItems.Any(item => item == i)).ToList(); SelectedItems.Clear(); SelectedItems.AddRange(items); await TriggerSelectedItemChanged(); }
/// <summary> /// 调用 OnQuery 回调方法获得数据源 /// </summary> protected async Task QueryData() { // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I29YK1 // TODO: 选中行目前不支持跨页 // 原因是选中行实例无法在翻页后保持 SelectedItems.Clear(); QueryData <TItem>?queryData = null; var queryOption = new QueryPageOptions() { PageIndex = PageIndex, PageItems = PageItems, SearchText = SearchText, SortOrder = SortOrder, SortName = SortName, Filters = Filters.Values, Searchs = GetSearchs(), SearchModel = SearchModel }; if (OnQueryAsync != null) { queryData = await OnQueryAsync(queryOption); } else if (UseInjectDataService) { queryData = await GetDataService().QueryAsync(queryOption); } if (queryData != null) { Items = queryData.Items; TotalCount = queryData.TotalCount; IsFiltered = queryData.IsFiltered; IsSorted = queryData.IsSorted; IsSearch = queryData.IsSearch; // 外部未过滤,内部自行过滤 if (!IsFiltered && Filters.Any()) { Items = Items.Where(Filters.Values.GetFilterFunc <TItem>()); TotalCount = Items.Count(); } // 外部未处理排序,内部自行排序 if (!IsSorted && SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(SortName)) { var invoker = SortLambdaCache.GetOrAdd(typeof(TItem), key => Items.GetSortLambda().Compile()); Items = invoker(Items, SortName, SortOrder); } } if (!IsRendered && SelectedRows != null) { SelectedItems.AddRange(Items.Where(i => SelectedRows.Contains(i))); } }
/// <summary> /// 点击 Header 选择复选框时触发此方法 /// </summary> /// <param name="state"></param> /// <param name="val"></param> protected virtual Task OnHeaderCheck(CheckboxState state, bool val) { SelectedItems.Clear(); if (state == CheckboxState.Checked && Items != null) { SelectedItems.AddRange(Items); } ItemCheckboxs?.ForEach(async checkbox => await checkbox.SetState(state)); return(Task.CompletedTask); }
/// <summary> /// Initializes a new instance of the <see cref="TagSelectViewModel"/> class. /// </summary> /// <param name="dialogService">Dialog service dependency.</param> /// <param name="tagService">Tag service dependency.</param> /// <param name="selectedTags">Alredy existing tags for editing.</param> /// <param name="allTags">All tags to select from.</param> public TagSelectViewModel(DialogService dialogService, CRUDService <Tag> tagService, IEnumerable <TagEdit> selectedTags, IList <TagEdit>?allTags = null) : base(dialogService) { this.tagService = tagService; AddTagCommand = new DelegateCommand(AddTagAsync); AllTags = new ObservableCollection <TagEdit>(allTags ?? tagService.GetProjected <TagEdit>()); SelectedItems.AddRange(AllTags.Intersect(selectedTags)); AllTags.CollectionChanged += AllTags_CollectionChanged; }
private void btnAdd_Click(object sender, EventArgs e) { var selectedItems = GetSelectedItems(lstAvailableItems); if (!selectedItems.Any()) { return; } SelectedItems.AddRange(selectedItems); BindData(); RaiseSelectedItemsChanged(); }
/// <summary> /// 更改组件数据源方法 /// </summary> /// <param name="items"></param> public void SetItems(IEnumerable <SelectedItem>?items) { Items = items; ResetItems(); // 重置选中项 SelectedItems.Clear(); if (items != null) { SelectedItems.AddRange(items.Where(i => i.Active)); } StateHasChanged(); }
public void SelectionChanged(SelectionChangedEventArgs args) { SelectedItems.AddRange(args.AddedItems.Cast <PresetItemViewModel>()); SelectedItems.RemoveRange(args.RemovedItems.Cast <PresetItemViewModel>()); if (args.AddedItems.Count == 0 && !SelectedItems.Any()) { eventAggregator.Publish(new Events.PresetItemsSelectionChanged(false)); } if (args.RemovedItems.Count == 0 && SelectedItems.Count == 1) { eventAggregator.Publish(new Events.PresetItemsSelectionChanged(true)); } }
private void UpdatePrivacy(UserPrivacySettingRules rules) { var disallowed = rules.Rules.FirstOrDefault(x => x is UserPrivacySettingRuleRestrictUsers) as UserPrivacySettingRuleRestrictUsers; if (disallowed == null) { disallowed = new UserPrivacySettingRuleRestrictUsers(new int[0]); } var users = ProtoService.GetUsers(disallowed.UserIds); BeginOnUIThread(() => { SelectedItems.AddRange(users); }); }
void SelectionChanged(object para) { var selectionEvent = (para as SelectionChangedEventArgs); if (selectionEvent.RemovedItems.Count > 0) { foreach (var toRemove in selectionEvent.RemovedItems.Cast <Mediafile>()) { SelectedItems.Remove(toRemove); } } if (selectionEvent.AddedItems.Count > 0) { SelectedItems.AddRange(selectionEvent.AddedItems.Cast <Mediafile>().ToList()); } }
public void SelectAll(ItemCollection items) { try { Updating = true; if (Mode == SelectionMode.Single) { throw new NotSupportedException("Cannot call SelectAll when in Single select mode"); } var toSelect = new List <object> (); foreach (var v in items) { if (!SelectedItems.Contains(v)) { toSelect.Add(v); } } if (toSelect.Count == 0) { return; } SelectedItems.AddRange(toSelect); if (SelectedItem == null) { SelectedItem = toSelect [0]; UpdateSelectorProperties(SelectedItem, Owner.Items.IndexOf(SelectedItem), Owner.GetValueFromItem(SelectedItem)); } Owner.SelectedItemsIsInvalid = true; Owner.RaiseSelectionChanged(Empty, toSelect); } finally { Updating = false; } }
/// <summary> /// 点击 Header 选择复选框时触发此方法 /// </summary> /// <param name="state"></param> /// <param name="val"></param> protected virtual Task OnHeaderCheck(CheckboxState state, TItem val) { switch (state) { case CheckboxState.Checked: // select all SelectedItems.Clear(); SelectedItems.AddRange(Items); // callback if (SelectedRowsChanged.HasDelegate) { SelectedRowsChanged.InvokeAsync(SelectedRows); } StateHasChanged(); break; case CheckboxState.UnChecked: // unselect all SelectedItems.Clear(); // callback if (SelectedRowsChanged.HasDelegate) { SelectedRowsChanged.InvokeAsync(SelectedRows); } StateHasChanged(); break; default: break; } return(Task.CompletedTask); }
private void OnSelectedItemsListChanged() { SelectedItems.Clear(); SelectedItems.AddRange(SelectedItemsList.Cast <IFileSystemInfo>()); }
/// <summary> /// 调用 OnQuery 回调方法获得数据源 /// </summary> protected async Task QueryData() { // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I29YK1 // 选中行目前不支持跨页 原因是选中行实例无法在翻页后保持 SelectedItems.Clear(); QueryData <TItem>?queryData = null; var queryOption = new QueryPageOptions() { IsPage = IsPagination, PageIndex = PageIndex, PageItems = PageItems, SearchText = SearchText, SortOrder = SortOrder, SortName = SortName, Filters = Filters.Values, Searchs = GetSearchs(), SearchModel = SearchModel }; if (OnQueryAsync != null) { queryData = await OnQueryAsync(queryOption); } else if (UseInjectDataService) { queryData = await GetDataService().QueryAsync(queryOption); } if (queryData != null) { Items = queryData.Items; if (IsTree) { KeySet.Clear(); if (TableTreeNode <TItem> .HasKey) { CheckExpandKeys(TreeRows); } if (KeySet.Count > 0) { TreeRows = new List <TableTreeNode <TItem> >(); foreach (var item in Items) { var node = new TableTreeNode <TItem>(item) { HasChildren = CheckTreeChildren(item), }; node.IsExpand = node.HasChildren && node.Key != null && KeySet.Contains(node.Key); if (node.IsExpand) { await RestoreIsExpand(node); } TreeRows.Add(node); } } else { TreeRows = Items.Select(item => new TableTreeNode <TItem>(item) { HasChildren = CheckTreeChildren(item) }).ToList(); } } TotalCount = queryData.TotalCount; IsFiltered = queryData.IsFiltered; IsSorted = queryData.IsSorted; IsSearch = queryData.IsSearch; // 外部未过滤,内部自行过滤 if (!IsFiltered && Filters.Any()) { Items = Items.Where(Filters.Values.GetFilterFunc <TItem>()); TotalCount = Items.Count(); } // 外部未处理排序,内部自行排序 if (!IsSorted && SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(SortName)) { var invoker = SortLambdaCache.GetOrAdd(typeof(TItem), key => LambdaExtensions.GetSortLambda <TItem>().Compile()); Items = invoker(Items, SortName, SortOrder); } } if (SelectedRows != null) { SelectedItems.AddRange(Items.Where(i => SelectedRows.Contains(i))); } }
private async Task SelectAll() { SelectedItems.AddRange(Items); await TriggerSelectedItemChanged(); }
public void SelectAll() { DeselectAll(); SelectedItems.AddRange(Enumerable.Range(0, _fansCache.Count)); NotifyDataSetChanged(); }