From 5a181c135f6be8acd0c6f4301a969c3a83d64849 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 29 Apr 2014 12:17:00 +0200 Subject: [PATCH 01/21] Open Collection Editor from PropertyGrid for Properties which implement ICollection (Resources, Children, Items, ...) --- .../Project/BasicMetadata.cs | 4 +- .../PropertyGrid/Editors/BoolEditor.xaml | 1 + .../Editors/FlatCollectionEditor.xaml.cs | 20 +++++++--- .../Editors/OpenCollectionEditor.xaml | 17 +++++++++ .../Editors/OpenCollectionEditor.xaml.cs | 38 +++++++++++++++++++ .../Project/WpfDesign.Designer.csproj | 4 ++ .../Project/PropertyGrid/EditorManager.cs | 7 ++++ .../Project/PropertyGrid/TypeHelper.cs | 5 ++- 8 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index d3d6ffcd18..91dbe48dd1 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -163,6 +163,8 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularProperty(typeof(Binding), "ElementName"); Metadata.AddPopularProperty(typeof(Binding), "Converter"); Metadata.AddPopularProperty(typeof(Binding), "XPath"); + + Metadata.AddPopularProperty(typeof(ItemsControl), "Items"); Metadata.AddValueRange(Block.LineHeightProperty, double.Epsilon, double.MaxValue); Metadata.AddValueRange(Canvas.BottomProperty, double.MinValue, double.MaxValue); @@ -219,7 +221,7 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.HideProperty(typeof(UIElement), "RenderSize"); Metadata.HideProperty(FrameworkElement.NameProperty); - Metadata.HideProperty(typeof(FrameworkElement), "Resources"); + //Metadata.HideProperty(typeof(FrameworkElement), "Resources"); Metadata.HideProperty(typeof(Window), "Owner"); //Metadata.DisablePlacement(typeof(Button)); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BoolEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BoolEditor.xaml index f088519992..5c05391fb0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BoolEditor.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BoolEditor.xaml @@ -3,5 +3,6 @@ xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" IsChecked="{Binding Value}" + Focusable="False" > 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 07f33783f9..bffd2a8f4e 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 @@ -57,18 +57,28 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors this.Owner = Application.Current.MainWindow; } + public Type GetItemsSourceType(Type t) + { + Type tp = t.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>)); + + return (tp != null ) ? tp.GetGenericArguments()[0] : null; + } + public void LoadItemsCollection(DesignItemProperty itemProperty) { _itemProperty = itemProperty; _componentService=_itemProperty.DesignItem.Services.Component; TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type); + + _type = _type ?? GetItemsSourceType(_itemProperty.ReturnType); + if (_type == null) { - PropertyGridView.IsEnabled=false; - ListBox.IsEnabled=false; + //PropertyGridView.IsEnabled=false; + //ListBox.IsEnabled=false; AddItem.IsEnabled=false; - RemoveItem.IsEnabled=false; - MoveUpItem.IsEnabled=false; - MoveDownItem.IsEnabled=false; + //RemoveItem.IsEnabled=false; + //MoveUpItem.IsEnabled=false; + //MoveDownItem.IsEnabled=false; } ListBox.ItemsSource = _itemProperty.CollectionElements; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml new file mode 100644 index 0000000000..346915708c --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml @@ -0,0 +1,17 @@ + + + + +