Skip to content

Commit b87b18b

Browse files
authored
Merge pull request #83 from simplic/FlatCollectionCombobox
Add a Combobox in FlatCollectonEditor.
2 parents 807dc11 + 18b7e4b commit b87b18b

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,21 @@
3939
SelectionChanged="ListBox_SelectionChanged" ItemTemplateSelector="{StaticResource CollectionTemplateSelector}">
4040
</ListBox>
4141
</Border>
42+
<ComboBox Name="ItemDataType"
43+
Grid.Column="1"
44+
Height="23"
45+
HorizontalAlignment="Left"
46+
VerticalAlignment="Top"
47+
Width="75" Margin="0,10,0,0">
48+
49+
</ComboBox>
4250
<Button
4351
Content="Add"
4452
Click="OnAddItemClicked"
4553
Grid.Column="1"
4654
Height="23"
4755
HorizontalAlignment="Left"
48-
Margin="0,12,0,0"
56+
Margin="0,40,0,0"
4957
Name="AddItem"
5058
VerticalAlignment="Top"
5159
Width="75" />
@@ -55,7 +63,7 @@
5563
Grid.Column="1"
5664
Height="23"
5765
HorizontalAlignment="Left"
58-
Margin="0,42,0,0"
66+
Margin="0,68,0,0"
5967
Name="RemoveItem"
6068
VerticalAlignment="Top"
6169
Width="75" />
@@ -65,7 +73,7 @@
6573
Grid.Column="1"
6674
Height="23"
6775
HorizontalAlignment="Left"
68-
Margin="0,72,0,0"
76+
Margin="0,96,0,0"
6977
Name="MoveUpItem"
7078
VerticalAlignment="Top"
7179
Width="75" />
@@ -75,10 +83,10 @@
7583
Grid.Column="1"
7684
Height="23"
7785
HorizontalAlignment="Left"
78-
Margin="0,102,0,0"
86+
Margin="0,124,0,0"
7987
Name="MoveDownItem"
8088
VerticalAlignment="Top"
81-
Width="75" />
89+
Width="75" RenderTransformOrigin="0.519,1.16" />
8290
<Border
8391
BorderBrush="Black"
8492
BorderThickness="0.75"

WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Windows.Controls;
2323
using System.Linq;
2424
using ICSharpCode.WpfDesign.Designer.themes;
25+
using System.Reflection;
2526

2627
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
2728
{
@@ -45,7 +46,7 @@ static FlatCollectionEditor()
4546
public FlatCollectionEditor()
4647
{
4748
SpecialInitializeComponent();
48-
49+
4950
this.Owner = Application.Current.MainWindow;
5051
}
5152

@@ -59,7 +60,6 @@ public void SpecialInitializeComponent()
5960
Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
6061
Application.LoadComponent(this, resourceLocator);
6162
}
62-
6363
this.InitializeComponent();
6464
}
6565

@@ -84,10 +84,33 @@ public void LoadItemsCollection(DesignItemProperty itemProperty)
8484

8585
ListBox.ItemsSource = _itemProperty.CollectionElements;
8686
}
87-
87+
88+
/// <summary>
89+
/// A method which fill a combobox with _type and the inherited classes.
90+
/// </summary>
91+
public void LoadItemsCombobox()
92+
{
93+
ItemDataType.Items.Add(_type);
94+
ItemDataType.SelectedItem = ItemDataType.Items[0];
95+
foreach (var items in GetInheritedClasses(_type))
96+
ItemDataType.Items.Add(items);
97+
98+
}
99+
100+
/// <summary>
101+
/// A Method to find all inherited classes.
102+
/// </summary>
103+
/// <param name="MyType">The type where we want the inherited classes.</param>
104+
/// <returns>All inherited classes.</returns>
105+
private IEnumerable<Type> GetInheritedClasses(Type MyType)
106+
{
107+
return Assembly.GetAssembly(MyType).GetTypes().Where(TheType => TheType.IsClass && !TheType.IsAbstract && TheType.IsSubclassOf(MyType));
108+
}
109+
88110
private void OnAddItemClicked(object sender, RoutedEventArgs e)
89111
{
90-
DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type));
112+
var comboboxItem = ItemDataType.SelectedItem;
113+
DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance((Type)comboboxItem));
91114
_itemProperty.CollectionElements.Add(newItem);
92115
}
93116

@@ -133,5 +156,9 @@ void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
133156
{
134157
PropertyGridView.PropertyGrid.SelectedItems = ListBox.SelectedItems.Cast<DesignItem>();
135158
}
159+
160+
161+
162+
136163
}
137164
}

WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void open_Click(object sender, RoutedEventArgs e)
5353

5454
var editor = new FlatCollectionEditor();
5555
editor.LoadItemsCollection(node.FirstProperty);
56+
editor.LoadItemsCombobox();
5657
editor.ShowDialog();
5758
}
5859
}

0 commit comments

Comments
 (0)