2222using System . Windows . Controls ;
2323using System . Linq ;
2424using ICSharpCode . WpfDesign . Designer . themes ;
25+ using System . Reflection ;
2526
2627namespace 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}
0 commit comments