- CatBytesAndCoffee
- Posts: 12
- Joined:
System.ComponentModel.EnumConverter
I attempted to use a System.ComponentModel.EnumConverter as described by https://brianlagunas.com/a-better-way-t ... ms-in-wpf/. It works great in Blend but it does not seem to be recognized when running in Unity. (The code doesn't appear to execute and I tried to put a breakpoint there but it wasn't recognized as a valid location.) Should I be able to use a converter like this?
-
sfernandez
Site Admin
- Posts: 3112
- Joined:
Re: System.ComponentModel.EnumConverter
You should be able to define a TypeConverter for your type the way it is explained in that article
Although we don't expose the EnumConverter class (could you please create a ticket for this?), I think you won't need it in this case, you can just return the string values you want from the enum value received (or using the Description attribute approach to make it more generic).
Code: Select all
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
public enum Status
Code: Select all
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value is MyEnumType)
{
MyEnumType enumValue = (MyEnumType)value;
switch (enumValue)
{
case Option1: return "This is the first option";
case Option2: return "This is the second option";
...
}
}
return string.Empty;
}
- CatBytesAndCoffee
- Posts: 12
- Joined:
Re: System.ComponentModel.EnumConverter
Thanks for the suggestion! I'll try it that way, and will raise that ticket on the EnumConverter class.
Ticket submitted: https://www.noesisengine.com/bugs/view.php?id=3679
Ticket submitted: https://www.noesisengine.com/bugs/view.php?id=3679
-
sfernandez
Site Admin
- Posts: 3112
- Joined:
Re: System.ComponentModel.EnumConverter
Thanks for the ticket
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest