/// <summary> /// resets the <see cref="IndexItems"/> /// </summary> /// <param name="datacontext"></param> private void UpdateData(object datacontext) { if (datacontext is IEnumerable <IndexItemModel> items) { var tempItems = items.OrderBy(x => x.Text, new AlphanumComparatorFast()) .Select(item => item.Text.First()) .Distinct() .ToDictionary(l => l.ToString(), l => items.Where(x => x.Text.StartsWith(l.ToString()))); foreach (var item in tempItems) { IndexItemModel mainIndex = null; if (char.IsDigit(item.Key.First())) { mainIndex = _indexEntries.Where(x => x.Text == "#").FirstOrDefault(); } else { mainIndex = _indexEntries.Where(x => x.Text == item.Key).FirstOrDefault(); } if (mainIndex == null) { Debug.WriteLine($"WARNING: {item.Key} not found"); continue; } item.Value.ForEach(it => mainIndex.SubItems.Add(it)); } var comparer = SortExpressionComparer <IndexItemModel> .Ascending(x => x.Compare(_indexSectionItems)); if (_disposables != null) { _disposables.Dispose(); } var sourceList = new SourceList <IndexItemModel>(); sourceList.AddRange(_indexEntries); _items = sourceList.Connect(); _items.Filter(_filter) .Sort(comparer) /*need this here because after filtering the list is incorrect ordered*/ .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _indexItems) .DisposeMany() .Subscribe(); _disposables = new CompositeDisposable(sourceList); RaisePropertyChanged(IndexItemsProperty, null, _indexItems); } }
/// <summary> /// scrolls the item into the view /// </summary> /// <param name="item"></param> private void ExecutePressedCommand(IndexItemModel item) { _contentIndexList.ScrollIntoView(item); }