private void TrySubscribeEnumerable(object obj) { var enumerable = obj as IEnumerable; if (enumerable == null) { var observable = Observable2.Coerce <object>(obj); if (observable == null) { SetScalarValue(obj); } else { var collection = new ObservableCollection <object>(); SetScalarValue(collection); source = observable; listSource = collection; subscribing = Dispatcher.CurrentDispatcher.BeginInvoke((Action)SubscribeCollection, DispatcherPriority.DataBind); } } else { listSource = enumerable; var dispatcher = Dispatcher.CurrentDispatcher; var notifier = new DispatchChangesEnumerable(dispatcher, DispatcherPriority.DataBind, enumerable); SetScalarValue(notifier); var notifyingSource = obj as INotifyCollectionChanged; if (notifyingSource != null) { NotifyCollectionChangedEventHandler handler = (sender, e) => notifier.OnCollectionChanged(e); notifyingSource.CollectionChanged += handler; subscription.Disposable = Disposable.Create(() => notifyingSource.CollectionChanged -= handler); } else { var observable = Observable2.Coerce <object>(obj); if (observable != null) { source = observable; subscribing = dispatcher.BeginInvoke((Action <DispatchChangesEnumerable>)SubscribeNotify, DispatcherPriority.DataBind, notifier); } } } }
private void SubscribeNotify(DispatchChangesEnumerable notifier) { Contract.Requires(notifier != null); Contract.Requires(source != null); var reset = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset); subscription.SetDisposableIndirectly(() => source.Subscribe( _ => notifier.OnCollectionChanged(reset), () => PresentationTraceSources.DataBindingSource.TraceEvent( TraceEventType.Verbose, 0, "Subscription: Notification binding completed."))); }