1

当列表很大时,过滤会变慢。有没有更快的方法来处理过滤器?目前这就是我所拥有的。

CollectionViewSource orderListCVS;

private void showCompletedRB(object sender, RoutedEventArgs e)
{
    CollectionView coll = orderListCVS.View as CollectionView;
    coll.Filter = null;
    orderListCVS.Filter += new FilterEventHandler(showCompletedFilter);
}

private void showCompletedFilter(object sender, FilterEventArgs e)
{
    Order order = e.Item as Order;
    if (order != null)
    {
        e.Accepted = (order.Status == Data.Status.Done);
    }
}
4

1 回答 1

1

您是否尝试过这种方式:

public partial class MainWindow : Window
{
    private ICollectionView orderListCVS;

    private List<Order> orders;

    public MainWindow()
    {
        InitializeComponent();
        orders = new List<Order>();
        orderListCVS = CollectionViewSource.GetDefaultView(orders);
    }
    private bool showCompletedFilter(object sender)
    {
        Order order = sender as Order;
        if (order != null)
        {
            return order.Status == Data.Status.Done;
        }

        return false;
    }

    private void showCompletedRB(object sender, RoutedEventArgs e)
    {
        orderListCVS.Filter = showCompletedFilter;
    }
}

这是使用collectionView 最常见的方式。

于 2013-10-11T08:11:26.007 回答