相关疑难解决方法(0)

WPF ICollectionView过滤

我编写了一个用于在ComboBox中过滤项目的代码:

我的问题是,你会怎么做?

我认为这种带反射的解决方案可能非常慢 ..

ICollectionView view = CollectionViewSource.GetDefaultView(newValue);
view.Filter += this.FilterPredicate;


private bool FilterPredicate(object value)
{            
    if (value == null)
        return false;

    if (String.IsNullOrEmpty(SearchedText))
        return true;            

    int index = value.ToString().IndexOf(
        SearchedText,
        0,
        StringComparison.InvariantCultureIgnoreCase);

    if ( index > -1) return true;

    return FindInProperties(new string[] { "Property1", "Property2" }, value, SearchedText);
}

private bool FindInProperties(string[] properties, object value, string txtToFind)
{
    PropertyInfo info = null;
    for (int i = 0; i < properties.Length; i++)
    {
        info = value.GetType().GetProperty(properties[i]);
        if …
Run Code Online (Sandbox Code Playgroud)

wpf performance filtering filter icollectionview

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

filter ×1

filtering ×1

icollectionview ×1

performance ×1

wpf ×1