From c045a08fee107c42bff7beabf890a216373e4d24 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 11 Aug 2013 21:16:02 +0200 Subject: [PATCH] - Flat Collection Editor now working - Implement INotifyCollectionChanged in XamlModelCollectionElementsCollection --- .../Editors/FlatCollectionEditor.xaml.cs | 11 ----------- .../XamlModelCollectionElementsCollection.cs | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs index 9596b30266..994d3066a0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs @@ -63,8 +63,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors { DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type)); _itemProperty.CollectionElements.Add(newItem); - - refreshList(); } private void OnRemoveItemClicked(object sender, RoutedEventArgs e) @@ -72,15 +70,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors var selItem = ListBox.SelectedItem as DesignItem; if (selItem != null) _itemProperty.CollectionElements.Remove(selItem); - - refreshList(); - } - - void refreshList() - { - var sel = ListBox.SelectedItem; - ListBox.ItemsSource = new ObservableCollection(_itemProperty.CollectionElements); - ListBox.SelectedItem = sel; } private void OnMoveItemUpClicked(object sender, RoutedEventArgs e) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs index b83db4808e..7099aa828d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs @@ -7,15 +7,18 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using ICSharpCode.WpfDesign.XamlDom; using ICSharpCode.WpfDesign.Designer.Services; +using System.Collections.Specialized; namespace ICSharpCode.WpfDesign.Designer.Xaml { - sealed class XamlModelCollectionElementsCollection : IList + sealed class XamlModelCollectionElementsCollection : IList, INotifyCollectionChanged { readonly XamlModelProperty modelProperty; readonly XamlProperty property; readonly XamlDesignContext context; + public event NotifyCollectionChangedEventHandler CollectionChanged; + public XamlModelCollectionElementsCollection(XamlModelProperty modelProperty, XamlProperty property) { this.modelProperty = modelProperty; @@ -45,6 +48,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml while (this.Count > 0) { RemoveAt(this.Count - 1); } + + if (CollectionChanged != null) + CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } public bool Contains(DesignItem item) @@ -77,7 +83,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml int index = IndexOf(item); if (index < 0) return false; + RemoveAt(index); + return true; } @@ -151,11 +159,17 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml { Debug.Assert(property.CollectionElements[index] == item.XamlObject); property.CollectionElements.RemoveAt(index); + + if (CollectionChanged != null) + CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index)); } void InsertInternal(int index, XamlDesignItem item) { property.CollectionElements.Insert(index, item.XamlObject); + + if (CollectionChanged != null) + CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); } sealed class InsertAction : ITransactionItem