我正在构建一个需要过滤ObservableCollection的Windows8 Metro应用程序。遗憾的是,WinRT-Framework中的CollectionViewSource-Class不支持过滤,所以我尝试使用IValueConverter来进行过滤。
我的XAML:
<RadioButton Content="this Week" GroupName="AppointmentFilter" IsChecked="True" Name="rbtnFilter"/>
<RadioButton Content="all" GroupName="AppointmentFilter"/>
<ListView ItemsSource="{Binding Appointments, ConverterParameter={Binding rbtnFilter.IsChecked}, Converter={StaticResource Filter}}"/>我的IValueConverter:
public class AppointmentListFilter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
ObservableCollection<VMAppointment> appointments = value as ObservableCollection<VMAppointment>;
bool filter = (bool)parameter;
if (filter)
{
return new ObservableCollection<VMAppointment>(appointments.Where(x => x.Date.CompareTo(DateTime.Now.AddDays(7)) <= 0));
}
else
{
return appointments;
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}在执行参数时,参数“IValueConverter”为空,不是布尔值。我做错了什么?
发布于 2012-08-08 00:29:13
如果绑定本身不支持绑定,则可以更改约会属性的类型,使其包含所需的参数。如果您的转换器只被调用一次-您可以尝试订阅ObservableProperty的CollectionChanged事件,并在每次发生时引发约会的PropertyChanged事件。
https://stackoverflow.com/questions/11847178
复制相似问题