Пример #1
0
        public CategoryFilterView()
        {
            InitializeComponent();
            // Define Filter that must be use.
            EqualFilterInitializer initializer = new EqualFilterInitializer();
            // Get FilterPresenter that connected to default collection view for Workspace.This.Products collection.
            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;
        }
Пример #2
0
        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (filter is not null)
            {
                filter.PropertyChanged -= filter_PropertyChanged;
                filter = null;
            }
            if (e.NewValue is OrdersVm vm)
            {
                FilterPresenter fpr = FilterPresenter.Get(vm.OrdersCollectionView);
                ;
                if (fpr.TryGetFilter("Employee", new EqualFilterInitializer(), out filter))
                {
#pragma warning disable CS8602 // Dereference of a possibly null reference.
                    VisualStateManager.GoToState(this, filter.IsActive ? "Filtered" : "Unfiltered", false);
                    filter.PropertyChanged += filter_PropertyChanged;
#pragma warning restore CS8602 // Dereference of a possibly null reference.
                }
            }
        }
Пример #3
0
        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            OrdersVm vm = e.NewValue as OrdersVm;

            if (vm != null)
            {
                FilterPresenter fpr = FilterPresenter.TryGet(vm.OrdersCollectionView);
                filter = fpr.TryGetFilter("Employee", new EqualFilterInitializer());
                if (filter != null)
                {
                    if (filter.IsActive)
                    {
                        VisualStateManager.GoToState(this, "Filtered", false);
                    }
                    else
                    {
                        VisualStateManager.GoToState(this, "Unfiltered", false);
                    }
                    filter.PropertyChanged += filter_PropertyChanged;
                }
            }
        }