相关疑难解决方法(0)

运营商'|' 不能应用于'System.Enum'和'System.Enum'类型的操作数

我可以|&等等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)

c# wpf

6
推荐指数
1
解决办法
3167
查看次数

标签 统计

c# ×1

wpf ×1