【发布时间】:2012-08-04 12:56:56
【问题描述】:
我正在构建一个 Windows 8 Metro 应用程序,我需要在其中过滤 ObservableCollection。遗憾的是,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 时,参数“parameter”为空,不是布尔值。我做错了什么?
【问题讨论】:
-
ConverterParameter 不支持任何绑定操作。
-
你确定 CollectionViewSource 不支持 WinRT 下的过滤吗?我找不到任何支持这一点的文档。
标签: c# xaml data-binding windows-runtime