I have at treeview TextBox, and I want convert my Enum:
Create a Value Converter
It takes your enum value and returns the filename of the appropriate icon.
[ValueConversion(typeof(AcceptationStatusGlobalFlag), typeof(string))]
public class AcceptationStatusGlobalFlagToIconFilenameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
switch ((AcceptationStatusGlobalFlag)value)
{
case AcceptationStatusGlobalFlag.Ready:
return "ready.jpg";
case AcceptationStatusGlobalFlag.NotReady:
return "notready.jpg";
case AcceptationStatusGlobalFlag.AcceptedByAdmin:
return "AcceptedByAdmin.jpg";
default:
return null;
}
// or
return Enum.GetName(typeof(AcceptationStatusGlobalFlag), value) + ".jpg";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
You will need to add a reference to this converter in your XAML
Replace your TextBlock
with an Image and tell it use your converter