我可以|和&等等enum,但不是Enum.为什么是这样?有没有办法解决?我正在尝试为WPF编写一个Enum标志转换器.
public class EnumFlagConverter : IValueConverter
{
public Enum CurrentValue;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var theEnum = value as Enum;
CurrentValue = theEnum;
return theEnum.HasFlag(parameter as Enum);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
Enum CurrentValue;
var theEnum = parameter as Enum;
if (CurrentValue.HasFlag(theEnum)) //this line is allowed
return CurrentValue &= ~theEnum; //~theEnum not allowed, neither is the &=
else …Run Code Online (Sandbox Code Playgroud)