I have at treeview TextBox, and I want convert my Enum:
You should use Binding with value converter: http://blogs.msdn.com/bencon/archive/2006/05/10/594886.aspx
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
<Window ... xmlns:converters="clr-namespace:App.Converters" ...>
<Window.Resources>
<converters:AcceptationStatusGlobalFlagToIconFilenameConverter x:Key="IconConverter"/>
</Window.Resources>
Replace your TextBlock
<TextBlock TextAlignment="Justify" VerticalAlignment="Center" Text="{Binding Path=AcceptationStatusGlobalFlag}" />
with an Image and tell it use your converter
<Image Source="{Binding AcceptationStatusGlobalFlag, Converter={StaticResource IconConverter}}"/>
The most easy solution to this, is to use a value convertor; so create an IValueConverter implementation that converts your enums to the corresponding images.
For more information see: http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx