Note that there are some explanatory texts on larger screens.

plurals
  1. POCollectionViewSource.Filter doesn't work
    primarykey
    data
    text
    <p>I have a window in my application with following resources:</p> <pre><code> &lt;Window.Resources&gt; &lt;ResourceDictionary&gt; &lt;Data:IssueRecords x:Key="DataSource"/&gt; &lt;CollectionViewSource x:Key="DataCollection" Source="{StaticResource DataSource}" Filter="CollectionViewSource_Filter"&gt; &lt;/CollectionViewSource&gt; &lt;/ResourceDictionary&gt; &lt;/Window.Resources&gt; </code></pre> <p>There is a standard event handler - a method, called CollectionViewSource_Filter and DataGrid, to apply filter to. After my window loads, everything works perfectly, including filters.</p> <p>For applying filters, I call a ReloadGrid method...</p> <pre><code> private void ReloadGrid(object sender, RoutedEventArgs e) { CollectionViewSource.GetDefaultView(GridData.ItemsSource).Refresh(); } </code></pre> <p>But, when user does any action, which makes changes to my database (delete, modify or create new), I need to reload those data sources, so I call...</p> <pre><code> private void ReloadDataSources() { var dataSource = this.FindResource("DataSource") as IStockRecords; dataSource.ReloadData(); var dataCollection = this.FindResource("DataCollection") as CollectionViewSource; dataCollection = new CollectionViewSource() { Source = dataSource }; dataCollection.Filter += new FilterEventHandler(CollectionViewSource_Filter); Binding binding = new Binding() { Source = dataCollection }; BindingOperations.SetBinding(GridData, DataGrid.ItemsSourceProperty, binding); } </code></pre> <p>I think, I do everything, what is needed to read actual data from database and reload the datasources in my window. But when I use any filter, after I call ReloadDataSources(), the filter event is not being used anymore. I debugged a source code and Refresh method doesn't invoke CollectionViewSource_Filter, even when I set FilterEventHandler...</p> <p>Am i missing anything? Thanks, JiKra</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload