【发布时间】:2015-12-24 09:07:38
【问题描述】:
我有Companies,我正在尝试使用criteria 过滤。每个Company 都有一个CurrentStatus,并且每次用户检查CheckBox 以定义过滤器时都会调用过滤方法。除了一件事之外,我目前几乎完全按照我想要的方式工作。这就是我所拥有的;
private void FilterCompanyType(object sender, RoutedEventArgs e)
{
criteria.Clear();
if (currentCheckBox.IsChecked == true)
{
criteria.Add(new Predicate<CompanyModel>(x => x.CurrentStatus == 1));
}
if (nonCurrentCheckBox.IsChecked == true)
{
criteria.Add(new Predicate<CompanyModel>(x => x.CurrentStatus == 0));
}
foreach (CheckBox checkBox in companyFilters.Children)
{
if (!CheckCheckBoxes())
{
dataGrid.ItemsSource = null;
compDetailsLabel.Content = string.Empty;
}
else
{
dataGrid.ItemsSource = CompanyICollectionView;
CompanyICollectionView.Filter = dynamic_Filter;
SetSelectedCompany(selectedIndex);
dataGrid.SelectedIndex = 0;
}
}
}
正如我所说,这工作正常,它适用于当用户想要查看Companies 的列表CurrentStaus == 1 或Companies 的列表CurrentStatus == 0。然而,目前用户看不到Companies的列表,如果CheckBoxes在CurrentStatus == 0和CurrentStatus == 1的位置被选中。
我已经尝试添加这个,但它不适用于 CheckBoxes 选中;
if (nonCurrentCheckBox.IsChecked == true && currentCheckBox.IsChecked == true)
{
criteria.Add(new Predicate<CompanyModel>(x => x.CurrentStatus == 0));
criteria.Add(new Predicate<CompanyModel>(x => x.CurrentStatus == 1));
}
这只是返回一个空的DataGrid。如何更改 Predicate 以允许两者?
【问题讨论】:
-
你可以试试
criteria.Add( new Predicate<CompanyModel>( x => ( x.CurrentStatus == 1 || x.CurrentStatus == 0 ) ) )两者都被检查了。 -
@bars222 不幸的是,使用它仍然导致
Companies没有显示在DataGrid中 -
您还应该将代码添加到之前的
if语句中。 if (currentCheckBox.IsChecked == true && nonCurrentCheckBox.IsChecked == false)