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}}"/>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…