Browse Source

- Flat Collection Editor now working

- Implement INotifyCollectionChanged in XamlModelCollectionElementsCollection
pull/58/head
jkuehner 13 years ago
parent
commit
c045a08fee
  1. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs
  2. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

11
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)); DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type));
_itemProperty.CollectionElements.Add(newItem); _itemProperty.CollectionElements.Add(newItem);
refreshList();
} }
private void OnRemoveItemClicked(object sender, RoutedEventArgs e) private void OnRemoveItemClicked(object sender, RoutedEventArgs e)
@ -72,15 +70,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
var selItem = ListBox.SelectedItem as DesignItem; var selItem = ListBox.SelectedItem as DesignItem;
if (selItem != null) if (selItem != null)
_itemProperty.CollectionElements.Remove(selItem); _itemProperty.CollectionElements.Remove(selItem);
refreshList();
}
void refreshList()
{
var sel = ListBox.SelectedItem;
ListBox.ItemsSource = new ObservableCollection<DesignItem>(_itemProperty.CollectionElements);
ListBox.SelectedItem = sel;
} }
private void OnMoveItemUpClicked(object sender, RoutedEventArgs e) private void OnMoveItemUpClicked(object sender, RoutedEventArgs e)

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

@ -7,15 +7,18 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using ICSharpCode.WpfDesign.XamlDom; using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services; using ICSharpCode.WpfDesign.Designer.Services;
using System.Collections.Specialized;
namespace ICSharpCode.WpfDesign.Designer.Xaml namespace ICSharpCode.WpfDesign.Designer.Xaml
{ {
sealed class XamlModelCollectionElementsCollection : IList<DesignItem> sealed class XamlModelCollectionElementsCollection : IList<DesignItem>, INotifyCollectionChanged
{ {
readonly XamlModelProperty modelProperty; readonly XamlModelProperty modelProperty;
readonly XamlProperty property; readonly XamlProperty property;
readonly XamlDesignContext context; readonly XamlDesignContext context;
public event NotifyCollectionChangedEventHandler CollectionChanged;
public XamlModelCollectionElementsCollection(XamlModelProperty modelProperty, XamlProperty property) public XamlModelCollectionElementsCollection(XamlModelProperty modelProperty, XamlProperty property)
{ {
this.modelProperty = modelProperty; this.modelProperty = modelProperty;
@ -45,6 +48,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
while (this.Count > 0) { while (this.Count > 0) {
RemoveAt(this.Count - 1); RemoveAt(this.Count - 1);
} }
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
} }
public bool Contains(DesignItem item) public bool Contains(DesignItem item)
@ -77,7 +83,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
int index = IndexOf(item); int index = IndexOf(item);
if (index < 0) if (index < 0)
return false; return false;
RemoveAt(index); RemoveAt(index);
return true; return true;
} }
@ -151,11 +159,17 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
{ {
Debug.Assert(property.CollectionElements[index] == item.XamlObject); Debug.Assert(property.CollectionElements[index] == item.XamlObject);
property.CollectionElements.RemoveAt(index); property.CollectionElements.RemoveAt(index);
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
} }
void InsertInternal(int index, XamlDesignItem item) void InsertInternal(int index, XamlDesignItem item)
{ {
property.CollectionElements.Insert(index, item.XamlObject); property.CollectionElements.Insert(index, item.XamlObject);
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
} }
sealed class InsertAction : ITransactionItem sealed class InsertAction : ITransactionItem

Loading…
Cancel
Save