public StringCollectionEditorWindow(CollectionEditorControl ctrl) { InitializeComponent(); baseControl = ctrl; foreach (var tmp in baseControl.NumerableValue) { myList.Items.Add(tmp); } //Visibilty of cmdAdd //var aa = baseControl.MyProperty.PropertyType.GetGenericArguments(); if (!HasDefaultConstructor(baseControl.MyProperty.PropertyType.GetGenericArguments()[0]) || baseControl.MyProperty.IsReadOnly) { cmdAdd.Visibility = Visibility.Collapsed; } if (baseControl.MyProperty.IsReadOnly) { cmdRemove.Visibility = Visibility.Collapsed; } }
public CollectionEditorWindow(CollectionEditorControl ctrl) { InitializeComponent(); baseControl = ctrl; if (baseControl.EditorOpeningCommand != null) { baseControl.EditorOpeningCommand.Execute(baseControl.NumerableValue); } this.DataContext = baseControl.DataContext; if (baseControl.NumerableValue != null) { foreach (var tmp in baseControl.NumerableValue) { myLst.Items.Add(tmp); } } //Visibilty of cmdAdd if (baseControl.MyProperty == null) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(baseControl.DataContext); baseControl.MyProperty = new WPG.Data.Property( baseControl.DataContext, properties[baseControl.NumerableTypeIdentifier]); //cmdAdd.Visibility = Visibility.Collapsed; //cmdRemove.Visibility = Visibility.Collapsed; //return; } bool canBeConstructed = false; if (baseControl.MyProperty.PropertyType.IsGenericType) { // check for generic list type Type[] typeArguments = baseControl.MyProperty.PropertyType.GetGenericArguments(); canBeConstructed = IsDefaultConstructible(typeArguments); } else if (baseControl.MyProperty.PropertyType.BaseType.IsGenericType) { // check BaseType for generic list type Type[] typeArguments = baseControl.MyProperty.PropertyType.BaseType.GetGenericArguments(); canBeConstructed = IsDefaultConstructible(typeArguments); } if (canBeConstructed) { //cmdAdd.Visibility = Visibility.Visible; //cmdRemove.Visibility = Visibility.Visible; } else { if (baseControl.MyProperty.PropertyType.GetGenericArguments().Length > 0) { if (!HasDefaultConstructor(baseControl.MyProperty.PropertyType.GetGenericArguments()[0]) || baseControl.MyProperty.IsReadOnly) { cmdAdd.Visibility = Visibility.Collapsed; } } if (baseControl.MyProperty.IsReadOnly) { cmdRemove.Visibility = Visibility.Collapsed; } } //myLst.ItemsSource = baseControl.NumerableValue; }