To further explore the features of the ItemsFilter library need a little explanation. Central class, FilterPresenter, as well as filter models, which he uses to filter, do not interact with the DataGrid, ItemsSelector or ItemsControl. Instead, he works with a collection view, connected to the FilterPresenter instance when it is created . Further, the collection view we can use wherever we need - perhaps in many places at the same time. Thus, for the interaction between FilterView and ItemsControl enough that they are both connected to the same instance of the collection (or collection view).

In the form of ProductsView control CategoryFilterView is out of DataGrid, but controls the display of the DataGrid ItemsSource.

How use.

    <DataGrid x:Name="productDataGrid"
                 ItemsSource="{Binding Path=Products,
                                    Source={StaticResource Workspace}}">
publicpartialclassCategoryFilterView : MultiValueFilterView {
    public CategoryFilterView() {
        // Define Filter that must be use.
        EqualFilterInitializer initializer = newEqualFilterInitializer();
        // // Get FilterPresenter that connected to the same collection Workspace.This.Products.
        FilterPresenter productsCollectionViewFilterPresenter = FilterPresenter.TryGet(Workspace.This.Products);
        // Get EqualFilter that use Category item property.
        EqualFilter filter = ((EqualFilter)(productsCollectionViewFilterPresenter.TryGetFilter("Category", initializer)));
        // Use instance of EqualFilter as Model.
        Model = filter;


How work.

An instance of FilterPresenter always bound to the collection view for which it was created. Because the property DataGrid.ItemsSource we bind directly to the collection itself, DataGrid extracts and uses the default collection view. In the call FilterPresenter.TryGet (Workspace. This. Products) is also transmitted directly collection, and the binding is assigned to the same instance of the default collection view. In fact, CategoryFilterView may even be in a separate window - filtering the collection view affects all elements using this view.

In the form of OrdersView drop-down list of Product uses an instance of the collection Workspace.This.Products, to which bound a ProductsView form, therefore, when the quick filter in the ProductsView form is active,  OrdersView cell (in edit mode ) displays only the filtered items in the Product drop-down list. For example, for the state of the filter shown in the previous topic, the view drop-down list will be such:


The fact that the filter is working directly with the the  collection view can easily use it in any of the controls, including those created by you.

Last edited Nov 9, 2013 at 5:03 AM by Mishkin, version 4