Exemplo n.º 1
0
        bool WrapFilter(object item)
        {
            FilterEventArgs    args     = new FilterEventArgs(item);
            FilterEventHandler handlers = FilterHandlersField.GetValue(this);

            if (handlers != null)
            {
                handlers(this, args);
            }

            return(args.Accepted);
        }
Exemplo n.º 2
0
        // Forward properties from the CollectionViewSource to the CollectionView
        void ApplyPropertiesToView(ICollectionView view)
        {
            if (view == null || _deferLevel > 0)
            {
                return;
            }

            ICollectionViewLiveShaping liveView = view as ICollectionViewLiveShaping;

            using (view.DeferRefresh())
            {
                int i, n;

                // Culture
                if (Culture != null)
                {
                    view.Culture = Culture;
                }

                // Sort
                if (view.CanSort)
                {
                    view.SortDescriptions.Clear();
                    for (i = 0, n = SortDescriptions.Count; i < n; ++i)
                    {
                        view.SortDescriptions.Add(SortDescriptions[i]);
                    }
                }
                else if (SortDescriptions.Count > 0)
                {
                    throw new InvalidOperationException(SR.Get(SRID.CannotSortView, view));
                }

                // Filter
                Predicate <object> filter;
                if (FilterHandlersField.GetValue(this) != null)
                {
                    filter = FilterWrapper;
                }
                else
                {
                    filter = null;
                }

                if (view.CanFilter)
                {
                    view.Filter = filter;
                }
                else if (filter != null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.CannotFilterView, view));
                }

                // GroupBy
                if (view.CanGroup)
                {
                    view.GroupDescriptions.Clear();
                    for (i = 0, n = GroupDescriptions.Count; i < n; ++i)
                    {
                        view.GroupDescriptions.Add(GroupDescriptions[i]);
                    }
                }
                else if (GroupDescriptions.Count > 0)
                {
                    throw new InvalidOperationException(SR.Get(SRID.CannotGroupView, view));
                }

                // Live shaping
                if (liveView != null)
                {
                    ObservableCollection <string> properties;

                    // sorting
                    if (liveView.CanChangeLiveSorting)
                    {
                        liveView.IsLiveSorting = IsLiveSortingRequested;
                        properties             = liveView.LiveSortingProperties;
                        properties.Clear();

                        if (IsLiveSortingRequested)
                        {
                            foreach (string s in LiveSortingProperties)
                            {
                                properties.Add(s);
                            }
                        }
                    }

                    CanChangeLiveSorting = liveView.CanChangeLiveSorting;
                    IsLiveSorting        = liveView.IsLiveSorting;

                    // filtering
                    if (liveView.CanChangeLiveFiltering)
                    {
                        liveView.IsLiveFiltering = IsLiveFilteringRequested;
                        properties = liveView.LiveFilteringProperties;
                        properties.Clear();

                        if (IsLiveFilteringRequested)
                        {
                            foreach (string s in LiveFilteringProperties)
                            {
                                properties.Add(s);
                            }
                        }
                    }

                    CanChangeLiveFiltering = liveView.CanChangeLiveFiltering;
                    IsLiveFiltering        = liveView.IsLiveFiltering;

                    // grouping
                    if (liveView.CanChangeLiveGrouping)
                    {
                        liveView.IsLiveGrouping = IsLiveGroupingRequested;
                        properties = liveView.LiveGroupingProperties;
                        properties.Clear();

                        if (IsLiveGroupingRequested)
                        {
                            foreach (string s in LiveGroupingProperties)
                            {
                                properties.Add(s);
                            }
                        }
                    }

                    CanChangeLiveGrouping = liveView.CanChangeLiveGrouping;
                    IsLiveGrouping        = liveView.IsLiveGrouping;
                }
                else
                {
                    CanChangeLiveSorting   = false;
                    IsLiveSorting          = null;
                    CanChangeLiveFiltering = false;
                    IsLiveFiltering        = null;
                    CanChangeLiveGrouping  = false;
                    IsLiveGrouping         = null;
                }
            }
        }