예제 #1
0
        private void ApplySortColumn(DataGridColumn column)
        {
            // If column was not sorted, we sort it ascending. If it was already sorted, we flip the sort direction.
            string sortColumn = this.GetColumnSortMemberPath(column);
            CustomSortDescription existingSortDescription = this.sortDescriptions.SingleOrDefault(sd => sd.PropertyName == sortColumn);

            if (existingSortDescription == null)
            {
                existingSortDescription = new CustomSortDescription
                {
                    PropertyName = sortColumn,
                    Direction    = ListSortDirection.Ascending,
                    Column       = column
                };
                this.sortDescriptions.Add(existingSortDescription);
            }
            else
            {
                existingSortDescription.Direction = (existingSortDescription.Direction == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending;
            }

            // If user is not pressing Shift, we remove all SortDescriptions except the current one.
            bool isShiftPressed = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;

            if (!isShiftPressed)
            {
                for (int i = this.sortDescriptions.Count - 1; i >= 0; i--)
                {
                    CustomSortDescription csd = this.sortDescriptions[i];
                    if (csd.PropertyName != sortColumn)
                    {
                        this.sortDescriptions.RemoveAt(i);
                    }
                }
            }

            this.RefreshData();
        }
예제 #2
0
        private void ApplySortColumn(DataGridColumn column)
        {
            // If column was not sorted, we sort it ascending. If it was already sorted, we flip the sort direction.
            string sortColumn = GetColumnSortMemberPath(column);
            CustomSortDescription existingSortDescription = sortDescriptions.SingleOrDefault(sd => sd.PropertyName == sortColumn);
            if (existingSortDescription == null)
            {
                existingSortDescription = new CustomSortDescription
                    {
                        PropertyName = sortColumn,
                        Direction = ListSortDirection.Ascending,
                        Column = column
                    };
                sortDescriptions.Add(existingSortDescription);
            }
            else
            {
                existingSortDescription.Direction = (existingSortDescription.Direction == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending;
            }

            // If user is not pressing Shift, we remove all SortDescriptions except the current one.
            bool isShiftPressed = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;
            if (!isShiftPressed)
            {
                for (int i = sortDescriptions.Count - 1; i >= 0; i--)
                {
                    CustomSortDescription csd = sortDescriptions[i];
                    if (csd.PropertyName != sortColumn)
                    {
                        sortDescriptions.RemoveAt(i);
                    }
                }
            }

            RefreshData();
        }