@@ -65,6 +65,9 @@ public void SpecialInitializeComponent()
6565
6666 public Type GetItemsSourceType ( Type t )
6767 {
68+ if ( t == typeof ( UIElementCollection ) )
69+ return typeof ( UIElement ) ;
70+
6871 Type tp = t . GetInterfaces ( ) . FirstOrDefault ( x => x . IsGenericType && x . GetGenericTypeDefinition ( ) == typeof ( ICollection < > ) ) ;
6972
7073 return ( tp != null ) ? tp . GetGenericArguments ( ) [ 0 ] : null ;
@@ -79,32 +82,40 @@ public void LoadItemsCollection(DesignItemProperty itemProperty)
7982 _type = _type ?? GetItemsSourceType ( _itemProperty . ReturnType ) ;
8083
8184 if ( _type == null ) {
82- AddItem . IsEnabled = false ;
85+ AddItem . IsEnabled = false ;
8386 }
8487
8588 ListBox . ItemsSource = _itemProperty . CollectionElements ;
8689 }
8790
88- /// <summary>
89- /// A method which fill a combobox with _type and the inherited classes.
90- /// </summary>
9191 public void LoadItemsCombobox ( )
9292 {
93- ItemDataType . Items . Add ( _type ) ;
94- ItemDataType . SelectedItem = ItemDataType . Items [ 0 ] ;
95- foreach ( var items in GetInheritedClasses ( _type ) )
96- ItemDataType . Items . Add ( items ) ;
97-
93+ if ( this . _type != null )
94+ {
95+ var types = new List < Type > ( ) ;
96+ types . Add ( _type ) ;
97+
98+ foreach ( var items in GetInheritedClasses ( _type ) )
99+ types . Add ( items ) ;
100+ ItemDataType . ItemsSource = types ;
101+ ItemDataType . SelectedItem = types [ 0 ] ;
102+
103+ if ( types . Count < 2 )
104+ {
105+ ItemDataType . Visibility = Visibility . Collapsed ;
106+ ListBoxBorder . Margin = new Thickness ( 10 ) ;
107+ }
108+ }
109+ else
110+ {
111+ ItemDataType . Visibility = Visibility . Collapsed ;
112+ ListBoxBorder . Margin = new Thickness ( 10 ) ;
113+ }
98114 }
99115
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 )
116+ private IEnumerable < Type > GetInheritedClasses ( Type type )
106117 {
107- return Assembly . GetAssembly ( MyType ) . GetTypes ( ) . Where ( TheType => TheType . IsClass && ! TheType . IsAbstract && TheType . IsSubclassOf ( MyType ) ) ;
118+ return AppDomain . CurrentDomain . GetAssemblies ( ) . Where ( x => ! x . IsDynamic ) . SelectMany ( x => x . GetTypes ( ) . Where ( y => y . IsClass && ! y . IsAbstract && y . IsSubclassOf ( type ) ) ) ;
108119 }
109120
110121 private void OnAddItemClicked ( object sender , RoutedEventArgs e )
0 commit comments