我在转换这种和平的代码时遇到问题。我尝试使用转换器,但完全没有运气。所有转换器都有这部分的问题“view.Filter = delegate(object item)”提前谢谢。
private void ApplyFilters()
{
// Get the view
ICollectionView view = CollectionViewSource.GetDefaultView(ItemsSource);
if (view != null)
{
// Create a filter
view.Filter = delegate(object item)
{
// Show the current object
bool show = true;
// Loop filters
foreach (KeyValuePair<string, string> filter in columnFilters)
{
object property = GetPropertyValue(item, filter.Key);
if (property != null)
{
// Check if the current column contains a filter
bool containsFilter = false;
if (IsFilteringCaseSensitive)
containsFilter = property.ToString().Contains(filter.Value);
else
containsFilter = property.ToString().ToLower().Contains(filter.Value.ToLower());
// Do the necessary things if the filter is not correct
if (!containsFilter)
{
show = false;
break;
}
}
}
// Return if it's visible or not
return show;
};
}
}