use*_*422 6 c# wpf xaml datagrid collectionviewsource
我想知道如何在单击按钮时刷新CollectionViewSource?
到目前为止我有
<Window.Resources>
<CollectionViewSource x:Key="cvsCustomers"
Source="{Binding CustomerCollection}"
Filter="CollectionViewSource_Filter" >
</CollectionViewSource>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
这创建了CollectionViewSource ......
<DataGrid HorizontalAlignment="Left"
Height="210"
Margin="47,153,0,0"
VerticalAlignment="Top" Width="410"
ItemsSource="{Binding Source={StaticResource cvsCustomers}}"
CanUserAddRows="False"
Run Code Online (Sandbox Code Playgroud)
这将源绑定到我的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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的视图中有一个过滤器,
一切似乎都在工作(项目正在被绑定到网格)但是如何刷新视图或网格以便我可以再次激活上面的函数以便网格被过滤?(真的按一下按钮)
谢谢
Roh*_*ats 14
呼叫Refresh()上View的财产CollectionViewSource得到它刷新.
如果您想在按钮单击时执行此操作,则需要先从窗口资源访问CollectionViewSource,然后在其View上调用refresh.
((CollectionViewSource)this.Resources["cvsCustomers"]).View.Refresh();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9946 次 |
| 最近记录: |