Hello,
Using a WPF PropertyGrid. and having a problem with using Editor Attributes in combination with a nested property. Basically, all property definitions with Editor Attributes defined at the root will work fine, however nested property definitions with Editor Attributes renders with nothing in it. The attached file shows the problem.
Here is the code which generates the property definitions:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
PropertyDefinitionCollection properties = EditorPropertyGrid.PropertyDefinitions;
ObservableCollection<
object
> testList = new ObservableCollection<
object
>();
UserDefinedEnumKeyValue first = new UserDefinedEnumKeyValue() { Key = "Custom Enum Control Prop", Value = new UserDefinedEnum() { Item = "UD3", Items = { "UD1", "UD2", "UD3", "UD4" } } };
testList.Add(first);
properties.Add(new PropertyDefinition()
{
DisplayName = first.Key,
Binding = new Binding("Value") { Source = first }
});
ParentKeyValue item = new ParentKeyValue() { ChildList = new List<
KeyValueBase
>() };
testList.Add(item);
PropertyDefinition parentPropertyDefinition = new PropertyDefinition()
{
DisplayName = item.Key,
Binding = new Binding("Value") { Source = item }
};
properties.Add(parentPropertyDefinition);
PropertyDefinitionCollection nestedProperties = parentPropertyDefinition.NestedProperties;
UserDefinedEnumKeyValue second = new UserDefinedEnumKeyValue() { Key = "Custom Enum Control Prop nested", Value = new UserDefinedEnum() { Item = "UD3", Items = { "UD1", "UD2", "UD3", "UD4" } } };
testList.Add(second);
nestedProperties.Add(new PropertyDefinition()
{
DisplayName = second.Key,
Binding = new Binding("Value") { Source = second }
});
EditorPropertyGrid.Item = testList;
}
Here are the model classes:
abstract class KeyValueBase
{
public string Key { get; set; }
public abstract void SetValue(string value);
}
class UserDefinedEnum : INotifyPropertyChanged
{
private List<
string
> _items = new List<
string
>();
public List<
string
> Items
{
get
{
return this._items;
}
//set NOTE not used for one way binding
//{
// if (this._items != value)
// {
// this._items = value;
// this.OnPropertyChanged("Items");
// }
//}
}
private string _item;
public string Item
{
get
{
return this._item;
}
set
{
if (this._item != value)
{
this._item = value;
this.OnPropertyChanged("Item");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
class UserDefinedEnumKeyValue : KeyValueBase
{
[Telerik.Windows.Controls.Data.PropertyGrid.Editor(typeof(EnumControl), Telerik.Windows.Controls.Data.PropertyGrid.EditorStyle.None)]
public UserDefinedEnum Value { get; set; }
public override void SetValue(string value)
{
}
}
class ParentKeyValue : KeyValueBase
{
public string Value { get; set; }
public List<
KeyValueBase
> ChildList { get; set; }
public override void SetValue(string value)
{
}
}
And here is the XAML for the EnumControl:
<
UserControl
x:Class
=
"TelerikWpfApp002.EnumControl"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
>
<
Grid
>
<
telerik:RadComboBox
SelectedValue
=
"{Binding Item, Mode=TwoWay}"
ItemsSource
=
"{Binding Items, Mode=OneWay}"
/>
</
Grid
>
</
UserControl
>
Thank you in advance for any help offered...