Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 5a181c1

Browse files
committed
Open Collection Editor from PropertyGrid for Properties which implement ICollection
(Resources, Children, Items, ...)
1 parent 1242324 commit 5a181c1

8 files changed

Lines changed: 88 additions & 8 deletions

File tree

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public static void Register()
163163
Metadata.AddPopularProperty(typeof(Binding), "ElementName");
164164
Metadata.AddPopularProperty(typeof(Binding), "Converter");
165165
Metadata.AddPopularProperty(typeof(Binding), "XPath");
166+
167+
Metadata.AddPopularProperty(typeof(ItemsControl), "Items");
166168

167169
Metadata.AddValueRange(Block.LineHeightProperty, double.Epsilon, double.MaxValue);
168170
Metadata.AddValueRange(Canvas.BottomProperty, double.MinValue, double.MaxValue);
@@ -219,7 +221,7 @@ public static void Register()
219221

220222
Metadata.HideProperty(typeof(UIElement), "RenderSize");
221223
Metadata.HideProperty(FrameworkElement.NameProperty);
222-
Metadata.HideProperty(typeof(FrameworkElement), "Resources");
224+
//Metadata.HideProperty(typeof(FrameworkElement), "Resources");
223225
Metadata.HideProperty(typeof(Window), "Owner");
224226

225227
//Metadata.DisablePlacement(typeof(Button));

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BoolEditor.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
IsChecked="{Binding Value}"
6+
Focusable="False"
67
>
78
</CheckBox>

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,28 @@ public FlatCollectionEditor()
5757
this.Owner = Application.Current.MainWindow;
5858
}
5959

60+
public Type GetItemsSourceType(Type t)
61+
{
62+
Type tp = t.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>));
63+
64+
return (tp != null ) ? tp.GetGenericArguments()[0] : null;
65+
}
66+
6067
public void LoadItemsCollection(DesignItemProperty itemProperty)
6168
{
6269
_itemProperty = itemProperty;
6370
_componentService=_itemProperty.DesignItem.Services.Component;
6471
TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type);
72+
73+
_type = _type ?? GetItemsSourceType(_itemProperty.ReturnType);
74+
6575
if (_type == null) {
66-
PropertyGridView.IsEnabled=false;
67-
ListBox.IsEnabled=false;
76+
//PropertyGridView.IsEnabled=false;
77+
//ListBox.IsEnabled=false;
6878
AddItem.IsEnabled=false;
69-
RemoveItem.IsEnabled=false;
70-
MoveUpItem.IsEnabled=false;
71-
MoveDownItem.IsEnabled=false;
79+
//RemoveItem.IsEnabled=false;
80+
//MoveUpItem.IsEnabled=false;
81+
//MoveDownItem.IsEnabled=false;
7282
}
7383

7484
ListBox.ItemsSource = _itemProperty.CollectionElements;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<UserControl
3+
x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.OpenCollectionEditor" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
4+
<Grid>
5+
<TextBlock
6+
Margin="0,0,20,0"
7+
Text="{Binding Value}" VerticalAlignment="Center" />
8+
<Button
9+
Width="15"
10+
Margin="0,0,1,0"
11+
HorizontalAlignment="Right"
12+
VerticalAlignment="Stretch"
13+
Content="..."
14+
Focusable="False"
15+
Click="open_Click" />
16+
</Grid>
17+
</UserControl>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
using ICSharpCode.WpfDesign.PropertyGrid;
17+
//using Xceed.Wpf.Toolkit;
18+
19+
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
20+
{
21+
[TypeEditor(typeof(ICollection))]
22+
public partial class OpenCollectionEditor : UserControl
23+
{
24+
public OpenCollectionEditor()
25+
{
26+
InitializeComponent();
27+
}
28+
29+
void open_Click(object sender, RoutedEventArgs e)
30+
{
31+
var node = this.DataContext as PropertyNode;
32+
33+
var editor = new FlatCollectionEditor();
34+
editor.LoadItemsCollection(node.FirstProperty);
35+
editor.ShowDialog();
36+
}
37+
}
38+
}

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
<DependentUpon>FlatCollectionEditor.xaml</DependentUpon>
9494
<SubType>Code</SubType>
9595
</Compile>
96+
<Compile Include="PropertyGrid\Editors\OpenCollectionEditor.xaml.cs">
97+
<DependentUpon>OpenCollectionEditor.xaml</DependentUpon>
98+
</Compile>
9699
<Compile Include="Translations.cs" />
97100
<Compile Include="Configuration\AssemblyInfo.cs" />
98101
<Compile Include="Controls\AdornerLayer.cs" />
@@ -252,6 +255,7 @@
252255
<ItemGroup>
253256
<Page Include="Extensions\RightClickContextMenu.xaml" />
254257
<Page Include="PropertyGrid\Editors\FlatCollectionEditor.xaml" />
258+
<Page Include="PropertyGrid\Editors\OpenCollectionEditor.xaml" />
255259
<Page Include="ThumbnailView\ThumbnailView.xaml" />
256260
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
257261
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>

src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/EditorManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public static FrameworkElement CreateEditor(DesignItemProperty property)
5151
}
5252
type = type.BaseType;
5353
}
54+
55+
foreach (var t in typeEditors) {
56+
if (t.Key.IsAssignableFrom(property.ReturnType)) {
57+
return (FrameworkElement)Activator.CreateInstance(t.Value);
58+
}
59+
}
60+
5461
if (editorType == null) {
5562
var standardValues = Metadata.GetStandardValues(property.ReturnType);
5663
if (standardValues != null) {

src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20+
using System.Collections;
2021
using System.Collections.Generic;
2122
using System.Linq;
2223
using System.Text;
@@ -93,7 +94,7 @@ public static IEnumerable<PropertyDescriptor> GetAvailableProperties(object elem
9394
foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(element))
9495
{
9596
if (!p.IsBrowsable) continue;
96-
if (p.IsReadOnly) continue;
97+
if (p.IsReadOnly && !typeof(ICollection).IsAssignableFrom(p.PropertyType)) continue;
9798
if (hiddenPropertiesOnWindow.Contains(p.Name)) continue;
9899
if (p.Attributes.OfType<ObsoleteAttribute>().Count() != 0) continue;
99100
yield return p;
@@ -103,7 +104,7 @@ public static IEnumerable<PropertyDescriptor> GetAvailableProperties(object elem
103104
{
104105
foreach(PropertyDescriptor p in TypeDescriptor.GetProperties(element)){
105106
if (!p.IsBrowsable) continue;
106-
if (p.IsReadOnly) continue;
107+
if (p.IsReadOnly && !typeof(ICollection).IsAssignableFrom(p.PropertyType)) continue;
107108
if (p.Attributes.OfType<ObsoleteAttribute>().Count()!=0) continue;
108109
yield return p;
109110
}

0 commit comments

Comments
 (0)