private void OnItemsSourceChanged(object sender, EventArgs args) { if (this.recordCollection != null) { this.Unsubscribe(); } this.recordCollection = this.AssociatedObject.ItemsSource as RecordCollection; if (this.recordCollection != null) { this.Subscribe(); } }
protected override void OnAttached() { base.OnAttached(); this.recordCollection = this.AssociatedObject.ItemsSource as RecordCollection; var descriptor = DependencyPropertyDescriptor.FromProperty( ItemsControl.ItemsSourceProperty, typeof(Control)); descriptor.AddValueChanged(this.AssociatedObject, this.OnItemsSourceChanged); if (this.recordCollection != null) { this.Subscribe(); } }