Esempio n. 1
0
            internal HierarchicalGroupByItemToggleColumnSortCommand(HierarchicalGroupByItem target)
                : base()
            {
                if (target == null)
                {
                    throw new ArgumentNullException("owner");
                }

                m_target = new WeakReference(target);

                if (target.ParentDataGridContext != null)
                {
                    m_dataGridContext = new WeakReference(target.ParentDataGridContext);
                }

                DataGridContext groupByItemDataGridContext = DataGridControl.GetDataGridContext(target);

                ToggleColumnSortCommand.ThrowIfNull(groupByItemDataGridContext, "groupByItemDataGridContext");

                DataGridControl dataGridControl = groupByItemDataGridContext.DataGridControl;

                ToggleColumnSortCommand.ThrowIfNull(dataGridControl, "dataGridControl");

                m_dataGridControl = new WeakReference(dataGridControl);
            }
Esempio n. 2
0
            protected override void DeferRestoreStateOnLevel(Disposer disposer)
            {
                var dataGridContext = this.DataGridContext;

                if (dataGridContext != null)
                {
                    ToggleColumnSortCommand.DeferRestoreStateOnLevel(disposer, dataGridContext);
                }
            }
Esempio n. 3
0
        protected static void DeferRestoreStateOnLevel(Disposer disposer, DataGridContext dataGridContext)
        {
            ToggleColumnSortCommand.ThrowIfNull(disposer, "disposer");
            ToggleColumnSortCommand.ThrowIfNull(dataGridContext, "dataGridContext");

            var parentDataGridContext = dataGridContext.ParentDataGridContext;

            // Defer the RestoreState of each DataGridContext of the same level
            // to ensure all the DataGridContext will be correctly restored once
            // all of them are completely resorted
            if (parentDataGridContext != null)
            {
                foreach (var childContext in parentDataGridContext.GetChildContexts())
                {
                    disposer.Add(childContext.DeferRestoreState(), DisposableType.DeferRestoreState);
                }
            }
        }
Esempio n. 4
0
        private bool ToggleColumnSort(ColumnBase column, bool resetSort)
        {
            ToggleColumnSortCommand.ThrowIfNull(column, "column");

            this.ValidateToggleColumnSort();

            using (var synchronizationContext = this.StartSynchronizing(this.GetSortDescriptionsSyncContext()))
            {
                this.ValidateSynchronizationContext(synchronizationContext);

                using (var disposer = new Disposer())
                {
                    this.DeferRestoreStateOnLevel(disposer);

                    // This will ensure that all DataGridCollectionViews mapped to the SortDescriptions collection will only refresh their sorting once!
                    var sortDescriptions = this.SortDescriptions;
                    disposer.Add(this.DeferResortHelper(sortDescriptions), DisposableType.DeferResort);

                    var    newSortDirection = ToggleColumnSortCommand.GetNextSortDirection(column.SortDirection);
                    string columnName       = column.FieldName;
                    int    insertionIndex;

                    if ((resetSort) &&
                        ((column.SortIndex == -1) || (sortDescriptions.Count > 1)))
                    {
                        insertionIndex = 0;

                        if (sortDescriptions.Count > 0)
                        {
                            sortDescriptions.Clear();
                        }

                        Debug.Assert(sortDescriptions.Count == 0);
                    }
                    else
                    {
                        for (insertionIndex = 0; insertionIndex < sortDescriptions.Count; insertionIndex++)
                        {
                            if (sortDescriptions[insertionIndex].PropertyName == columnName)
                            {
                                break;
                            }
                        }
                    }

                    if (insertionIndex < sortDescriptions.Count)
                    {
                        if (newSortDirection == SortDirection.None)
                        {
                            sortDescriptions.RemoveAt(insertionIndex);
                        }
                        else
                        {
                            sortDescriptions[insertionIndex] = new SortDescription(columnName, ToggleColumnSortCommand.Convert(newSortDirection));
                        }
                    }
                    else if (newSortDirection != SortDirection.None)
                    {
                        sortDescriptions.Add(new SortDescription(columnName, ToggleColumnSortCommand.Convert(newSortDirection)));
                    }
                }
            }

            return(true);
        }