我在 WPF 中使用 MarkupConverters 将枚举值解析为人类可读的字符串。
ASP.NET 和 ASP.NET GridView 或 DevExpress ASPxGridView 有没有办法在 WPF 中做同样的事情?
ASP.NET 中类似的东西(来自 WPF):
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace Converters
{
public class PriorityToStringConverter
: MarkupExtension, IValueConverter
{
public PriorityToStringConverter()
{
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is byte)
{
switch ((byte)value)
{
case 0:
return "Very high";
case 1:
return "High";
case 2:
return "Normal";
case 3:
return "Low";
case 4:
return "Very low";
default:
return value;
}
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}