/// <summary>
        ///     Create model for FilterControl, if it is possible in current state.
        /// </summary>
        /// <returns>Instance of FilterControlVm or null.</returns>
        protected virtual FilterControlVm CreateModel()
        {
            FilterControlVm vm = null;

            filterPresenter = Parent == null ? null : FilterPresenter.TryGet(ParentCollection);
            if (filterPresenter != null)
            {
                vm = filterPresenter.TryGetFilterControlVm(Key, FilterInitializersManager);
            }
            return(vm);
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes the filter view model.
        /// </summary>
        protected override FilterControlVm CreateModel()
        {
            FilterControlVm vm = null;

            filterPresenter = Parent == null ? null : FilterPresenter.TryGet(ParentCollection);
            if (filterPresenter != null)
            {
                if (Key == null)
                {
                    var columnHeader = this.GetParent <DataGridColumnHeader>();
                    if (columnHeader == null)
                    {
                        return(null);
                    }
                    var column = columnHeader.Column;
                    if (column == null)
                    {
                        return(null);
                    }
                    var dataGrid = columnHeader.GetParent <DataGrid>();
                    if (dataGrid == null)
                    {
                        return(null);
                    }
                    if (column.DisplayIndex >= dataGrid.Columns.Count)
                    {
                        return(null);
                    }
                    IEnumerable <FilterInitializer> initializers = GetInitializers(column) ?? FilterInitializersManager;
                    var key = GetColumnKey(column);
                    vm = filterPresenter.TryGetFilterControlVm(key, initializers);
                }
                else
                {
                    IEnumerable <FilterInitializer> initializers = FilterInitializersManager;
                    vm = filterPresenter.TryGetFilterControlVm(Key, initializers);
                }
                if (vm != null)
                {
                    vm.IsEnable = true;
                }
            }
            return(vm);
        }
Esempio n. 3
0
        // <summary>
        // Returns FilterPresenter, connected to a pass source .
        // If pass instance of ICollectionView, FilterPresenter connected to passed instance, otherwise, filterPresenter connected to default view for passed collection.
        // </summary>
        // <param name="source">ICollectionView for source or source</param>
        // <returns>FilterPresenter, connected to source, or null if source is null.</returns>
        public static FilterPresenter TryGet(IEnumerable source)
        {
            if (source == null)
            {
                return(null);
            }
            var sourceCollectionView = source as ICollectionView;

            if (sourceCollectionView == null)
            {
                sourceCollectionView = CollectionViewSource.GetDefaultView(source);
            }
            FilterPresenter instance = null;

            //GC.Collect();
            foreach (var entry in filterPresenters.ToArray())
            {
                if (!entry.Value.IsAlive)
                {
                    filterPresenters.Remove(entry.Key);
                }
            }
            if (filterPresenters.ContainsKey(sourceCollectionView))
            {
                var wr = filterPresenters[sourceCollectionView];
                instance = wr.Target as FilterPresenter;
            }
            if (instance == null)
            {
                instance = new FilterPresenter(sourceCollectionView);
                if (filterPresenters.ContainsKey(sourceCollectionView))
                {
                    filterPresenters[sourceCollectionView] = new WeakReference(instance);
                }
                else
                {
                    filterPresenters.Add(sourceCollectionView, new WeakReference(instance));
                }
            }
            return(instance);
        }
Esempio n. 4
0
            internal DisposeItemsDeferRefresh(FilterPresenter filterVm)
            {
                filterPr = filterVm;
                var cv = filterPr.CollectionView as IEditableCollectionView;

                if (cv != null)
                {
                    if (cv.IsAddingNew)
                    {
                        cv.CommitNew();
                    }
                    if (cv.IsEditingItem)
                    {
                        cv.CommitEdit();
                    }
                }
                if (filterPr.itemsDeferRefreshCount == 0)
                {
                    filterPr.itemsDeferRefresh = filterPr.CollectionView.DeferRefresh();
                }
                filterPr.itemsDeferRefreshCount++;
            }