0
我的組合框綁定到一個枚舉集合。我試圖從顯示中篩選出一些枚舉。用於IEnumerable枚舉的轉換器
我嘗試了下面的內容,但它沒有過濾掉任何東西,它只是返回原始集合。
<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));
}
}
請問我怎樣想的轉換器應用到狀態的資源或轉換一個枚舉集
您應該使用'&&'而不是'||'。 – juharr
@juharr謝謝Homie !!!! – Master