is it possible somehow to decorate Enum values so it would display multiple words in the dropdown?
Something like this:
public enum MyList
{
Black,
White,
[Description("Rather Not Say")]
Unknown
}
Regards,
Rodrigo
1 Answer, 1 is accepted
0
Yana
Telerik team
answered on 23 Oct 2020, 09:23 AM
Hi Rodrigo,
You can use a Converter Attribute to convert the enum type to / from a string and return the custom text, for example:
publicclassMyListToStringConverter : IPropertyConverter
{
publicobjectConvert(objectvalue)
{
if (value != null)
{
switch ((MyList)value)
{
case MyList.Black:
return"Black";
case MyList.White:
return"White";
case MyList.Unknown:
return"Rather Not Say";
default:
returnnull;
}
}
else
{
returnnull;
}
}
publicobjectConvertBack(objectvalue)
{
if (value != null)
{
switch ((string)value)
{
case"White":
return MyList.White;
case"Black":
return MyList.Black;
case"Rather Not Say":
return MyList.Unknown;
default:
returnnull;
}
}
else
{
returnnull;
}
}
}
Then use the converter in the source class definition:
[DisplayOptions(Header = "My List")]
[Converter(typeof(MyListToStringConverter))]
public MyList MyListProperty
{
get { returnthis.myListProperty; }
set
{
if (value != this.myListProperty)
{
this.myListProperty = value;
OnPropertyChanged();
}
}
}
I hope such an approach would be suitable for the scenario you have.
Regards,
Yana
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.