protected virtual TableSectionViewModel AddSection(TableSectionViewModel section) { if (section == null) { throw new ArgumentNullException(nameof(section)); } Sections.Add(section); return(section); }
protected virtual TableSectionViewModel AddSection(string name, bool showHeader = true, bool isVisible = true) { var section = new TableSectionViewModel(name, showHeader) { IsVisible = isVisible }; Sections.Add(section); return(section); }
public ItemPickerTableViewModel(IItemSource <T> itemSource, INavigationService navigationService, ISchedulerService scheduler) : base(navigationService, scheduler) { _defaultSection = AddSection(); var sortedList = itemSource.GetAll(); sortedList.ForEach(s => { var section = GetItemSection(s); if (section == null) { throw new NotSupportedException("Unable to return a section for the supplied item."); } var itemView = CreateItemViewModel(s); section.AddCell(itemView); }); }
private void RemoveSection(TableSectionViewModel obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } var view = _tableSectionViewModelMap[obj]; foreach (var cell in obj.Cells) { RemoveCell(view, cell); } _tableCellCollectionSectionMap.Remove(obj.Cells); _tableSectionViewModelMap.Remove(obj); _tableSectionViewMap.Remove(view); _tableView.Root.Remove(view); }
private TableSection CreateSectionView(TableSectionViewModel svm) { TableSection section; if (!string.IsNullOrWhiteSpace(svm.Name)) { section = new TableSection(svm.Name); } else { section = new TableSection(); } foreach (var cell in svm.Cells) { _pageManager.Disposibles.Add(cell.Visibility.Subscribe((visible) => { var visibleIndex = VisibleIndexOf(svm.Cells, cell); if (visible) { AddCell(section, cell, visibleIndex); } else { RemoveCell(section, cell); } })); } svm.Cells.Where(cv => cv.IsVisible).ForEach((c) => { var visibleIndex = VisibleIndexOf(svm.Cells, c); AddCell(section, c, visibleIndex); }); return(section); }
private void AddSection(TableSectionViewModel obj, int sectionIndex) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } var view = CreateSectionView(obj); _tableSectionViewModelMap.Add(obj, view); _tableSectionViewMap.Add(view, obj); _tableCellCollectionSectionMap.Add(obj.Cells, view); if (_tableView.Root.Count == 0) { _tableView.Root.Add(view); } else { // We need to insert somewhere. _tableView.Root.Insert(sectionIndex, view); } _pageManager.Disposibles.Add(Observable.FromEventPattern <NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs> ( h => obj.Cells.CollectionChanged += h, h => obj.Cells.CollectionChanged -= h ).Subscribe((args) => { // The cell collection has changed, so we need to track where abouts this cell change needs to go... // Find the appropriate actual section that this relates by mapping from the source observable collection // to the applicable table section view model if (args.Sender != null) { // We should probably check that the section is actually visible before doing the cell add here // It is possible that things will be added to an invisible section before it is shown. var section = _tableCellCollectionSectionMap[args.Sender]; var sectionViewModel = _tableSectionViewMap[section]; if (args.EventArgs.Action == NotifyCollectionChangedAction.Add) { var cellModels = args.EventArgs.NewItems.Cast <TableCellViewModel>(); cellModels.ForEach(cm => { var index = VisibleIndexOf(sectionViewModel.Cells, cm); AddCell(section, cm, index); }); } else if (args.EventArgs.Action == NotifyCollectionChangedAction.Remove) { var cellModels = args.EventArgs.OldItems.Cast <TableCellViewModel>(); cellModels.ForEach(cm => { var index = VisibleIndexOf(sectionViewModel.Cells, cm); RemoveCell(section, cm); }); } else if (args.EventArgs.Action == NotifyCollectionChangedAction.Reset) { var itemsToRemove = new List <Cell>(section.ToArray()); foreach (var cell in itemsToRemove) { var cellModel = _tableCellReverseViewModelMap[cell]; RemoveCell(section, cellModel); } } } })); }
private int VisibleIndexOf(ObservableCollection <TableSectionViewModel> sections, TableSectionViewModel section) { var actualIndex = sections.Where(s => s.IsVisible).ToList(); return(actualIndex.IndexOf(section)); }