Retrieve Collections and Enums Selected Value WPF Property Grid
I am using WPF PropertyGrid (http://www.codeplex.com/wpg) in my project. But i have some problems with this component.
1) I can show my IList collections in a ComboBox. But i can't retrieve selected value. How can i get selected value?
2) Enums are automatically shown in combobox, but i can't retrieve selected value like #1.
Can you help me?
This is my collection property
public class Contact {
// Other properties
[TypeConverter(typeof(MyConverter))]
public string Cities
{
get;
set;
}
}
This is my converter class
class MyConverter : TypeConverter
{
public override bool
GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection
GetStandardValues(ITypeDescriptorContext context)
{
List<string> list = new List<string>();
list.Add("Istanbul");
list.Add("Ankara");
list.开发者_如何学运维Add("Izmir");
StandardValuesCollection cols = new
StandardValuesCollection(list);
return cols;
}
}
When i set my Contact class's instance to WPF PropertyGrid's Instance property, i couldn't see any combox. But if i set my object to .Net PropertyGrid i can see this solution works well.
So i think this PG doesn't support TypeConverts, so what can i do?
Does WPF propertygrid support TypeConverters? The way it was done in Winforms PG was you could write a TypeConverter and add that as attribute to your property. The TypeConverter then could specify the StandardValuesCollection. So in your object you have property which takes one value and your converter specifies the collection of the possible values.
精彩评论