protected virtual void SetItemsSource(IEnumerable value) { if (Equals(_itemsSource, value)) { return; } if (_subscription != null) { _subscription.Dispose(); _subscription = null; } _itemsSource = value; if (_itemsSource != null && !(_itemsSource is IList)) { MvxBindingTrace.Trace(MvxTraceLevel.Warning, @"Binding to IEnumerable rather than IList - this can be inefficient, especially for large lists"); } var newObservable = _itemsSource as INotifyCollectionChanged; if (newObservable != null) { _subscription = newObservable.WeakSubscribe(OnItemsSourceCollectionChanged); } NotifyDataSetChanged(); }
public void SetInternalItemsSource(IEnumerable itemsSourceEnumerable) { if (ReferenceEquals(_itemsSource, itemsSourceEnumerable) && !ReloadOnAllItemsSourceSets) { return; } _subscription?.Dispose(); _subscription = null; _itemsSource = itemsSourceEnumerable ?? Enumerable.Empty <object>(); if (_itemsSource != null && !(_itemsSource is IList)) { MvxBindingTrace.Trace(MvxTraceLevel.Warning, "Binding to IEnumerable rather than IList - this can be inefficient, especially for large lists"); } var newObservable = _itemsSource as INotifyCollectionChanged; if (newObservable != null) { _subscription = newObservable.WeakSubscribe(OnItemsSourceCollectionChanged); } OnItemsSourceCollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
//----------------------------------------------------- #region Construction public CollectionView(IList sourceCollection) { _sourceCollection = sourceCollection ?? throw new ArgumentNullException(nameof(sourceCollection)); _groups = new FastObservableCollection <IGroupData>(); Groups = new ReadOnlyObservableCollection <IGroupData>(_groups); _groupDescriptions = new FastObservableCollection <GroupDescription>(); GroupDescriptions.CollectionChanged += _groupDescriptions_CollectionChanged; _sortDescriptions = new FastObservableCollection <SortDescription>(); SortDescriptions.CollectionChanged += _sortDescriptions_CollectionChanged; var newObservable = _sourceCollection as INotifyCollectionChanged; if (newObservable != null) { _subscription = newObservable.WeakSubscribe(OnSourceCollection_CollectionChanged); } Init(); }
public async Task <IDisposable> Connect(InternalObservableCollection <T> collection) { MvxNotifyCollectionChangedEventSubscription subscription = null; await _dispatcher.ExecuteOnMainThreadAsync(() => { lock (_lock) { collection.LockedAction(content => { _items.ReplaceWith(content); subscription = content.WeakSubscribe(UiCollectionChanged); }); } }).ConfigureAwait(false); return(subscription); }