WPF DataGrid的过滤 - 刷新CollectionViewSource刷新 [英] WPF DataGrid Filtering - Refreshing CollectionViewSource Refreshing

查看:3042
本文介绍了WPF DataGrid的过滤 - 刷新CollectionViewSource刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么能刷新CollectionViewSource点击一个按钮时?

I want to know how I can refresh a CollectionViewSource when a button is clicked?

到目前为止,我有

<Window.Resources>
    <CollectionViewSource x:Key="cvsCustomers"
                          Source="{Binding CustomerCollection}" 
                          Filter="CollectionViewSource_Filter" >
    </CollectionViewSource>
</Window.Resources>



它创建CollectionViewSource ...

Which creates the CollectionViewSource...

<DataGrid HorizontalAlignment="Left" 
              Height="210" 
              Margin="47,153,0,0"
              VerticalAlignment="Top" Width="410"
              ItemsSource="{Binding Source={StaticResource cvsCustomers}}"
              CanUserAddRows="False"

结合源头上我的Datagrid

Which binds the source to my Datagrid

    private void CollectionViewSource_Filter(object sender, FilterEventArgs e)
    {
        Customer t = e.Item as Customer;
        if (t != null)
        // If filter is turned on, filter completed items.
        {
            if (t.Name.Contains(txtSearch.Text))
            {
                e.Accepted = true;
            }
            else
            {
                e.Accepted = false;
            }
        }
    }



在我看来,一个过滤器

And a filter in my View,

一切似乎是工作(项目被一定到网格),但我怎么刷新视图或网格,以便我可以解雇上述功能再次使电网也得到过滤? (通过点击一个按钮真的)

Everything seems to be working (items are being bounded to the grid) but how do I refresh the view or grid so I can fire of the above function again so the grid does get filtered? (by a button click really)

感谢

推荐答案

呼叫< STRONG> 刷新() <上/ STRONG> 查看 属性的 CollectionViewSource 以得到它刷新。

Call Refresh() on View property of CollectionViewSource to get it refreshed.

如果你想这样做就按一下按钮,你需要首先从窗口资源访问CollectionViewSource然后调用视图刷新。

In case you want to do it on button click, you need to access CollectionViewSource from window resources first and then call refresh on its View.

((CollectionViewSource)this.Resources["cvsCustomers"]).View.Refresh();

这篇关于WPF DataGrid的过滤 - 刷新CollectionViewSource刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆