private static void SetExtension(DependencyObject obj, PanelExtension value) { obj.SetValue(ExtensionProperty, value); }
private static void OnItemsSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var panel = sender as Panel; if (panel == null) { throw new InvalidOperationException("Codify.Controls.PanelExtension.ItemsSource property can only be attached to a System.Windows.Controls.Panel."); } var ext = GetExtension(panel); if (ext == null) { SetExtension(panel, ext = new PanelExtension()); } var oldSource = e.OldValue as INotifyCollectionChanged; var newSource = e.NewValue as INotifyCollectionChanged; if (oldSource != null) { oldSource.CollectionChanged -= ext.OnItemsSourceCollectionChanged; panel.Children.Clear(); ext._delayItemsQueue.Clear(); } if (newSource != null) { newSource.CollectionChanged += ext.OnItemsSourceCollectionChanged; ext.AddItems(newSource as IEnumerable); } }