枚举的IEnumerable的转换器

本文关键字:转换器 IEnumerable 枚举 | 更新日期: 2023-09-27 18:25:17

我的组合框绑定到一个枚举集合。我正在尝试从显示中筛选出一些枚举。

我尝试了以下操作,但它不会过滤掉任何内容,只是返回原始集合。

<telerik:GridViewComboBoxColumn Header="Occurences" 
                                ItemsSource="{Binding Source={StaticResource ScheduleItems}, 
                                Converter={StaticResource ScheduleItemsEnumConverter}, Mode=OneWay}" />
public class ScheduleItemsEnumConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var collection = ((IEnumerable<LoanCalculator.ScheduleItems>)value).Cast<LoanCalculator.ScheduleItems>();
        collection  =
            collection.Where(
                x =>
                    !x.Equals(LoanCalculator.ScheduleItems.CapitalizedFee) ||
                    !x.Equals(LoanCalculator.ScheduleItems.CapitalizedInsurance) ||
                    !x.Equals(LoanCalculator.ScheduleItems.CapitalizedInterest));
        return collection;
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

我知道where子句是可以的,因为填充组合框的其他方法运行良好。

public IEnumerable<LoanCalculator.ScheduleItems> EventTypes
{
    get
    {
        return
            Enum.GetValues(typeof(LoanCalculator.ScheduleItems))
                .Cast<LoanCalculator.ScheduleItems>()
                .Where(
                    x =>
                        !x.Equals(LoanCalculator.ScheduleItems.CapitalizedFee) ||
                        !x.Equals(LoanCalculator.ScheduleItems.CapitalizedInsurance) ||
                        !x.Equals(LoanCalculator.ScheduleItems.CapitalizedInterest));
    }
}

请问我应该如何将转换器应用于状态资源或转换枚举集合

枚举的IEnumerable的转换器

您的逻辑是错误的。你想"answers"条件不"或"他们"。您也不需要Cast<LoanCalculator.ScheduleItems>

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    return  ((IEnumerable<LoanCalculator.ScheduleItems>)value)
        .Where(
            x =>
                !x.Equals(LoanCalculator.ScheduleItems.CapitalizedFee) &&
                !x.Equals(LoanCalculator.ScheduleItems.CapitalizedInsurance) &&
                !x.Equals(LoanCalculator.ScheduleItems.CapitalizedInterest));
}