Пример #1
0
        //TODO Implement
        internal void ApplyState()
        {
            /*
            // Common States
            if (IsPressed && DataGridColumnHeader._dragMode != DragMode.Resize)
            {
                VisualStates.GoToState(this, useTransitions, VisualStates.StatePressed, VisualStates.StateMouseOver, VisualStates.StateNormal);
            }
            else if (IsMouseOver && DataGridColumnHeader._dragMode != DragMode.Resize)
            {
                VisualStates.GoToState(this, useTransitions, VisualStates.StateMouseOver, VisualStates.StateNormal);
            }
            else
            {
                VisualStates.GoToState(this, useTransitions, VisualStates.StateNormal);
            }

            // Sort States
            CurrentSortingState = null;
            if (OwningGrid != null
                && OwningGrid.DataConnection != null
                && OwningGrid.DataConnection.AllowSort)
            {
                SortDescription? sort = OwningColumn.GetSortDescription();

                if (sort.HasValue)
                {
                    CurrentSortingState = sort.Value.Direction;
                    if (CurrentSortingState == ListSortDirection.Ascending)
                    {
                        VisualStates.GoToState(this, useTransitions, VisualStates.StateSortAscending, VisualStates.StateUnsorted);
                    }
                    if (CurrentSortingState == ListSortDirection.Descending)
                    {
                        VisualStates.GoToState(this, useTransitions, VisualStates.StateSortDescending, VisualStates.StateUnsorted);
                    }
                }
                else
                {
                    VisualStates.GoToState(this, useTransitions, VisualStates.StateUnsorted);
                }
            }
            */

            CurrentSortingState = null;
            if (OwningGrid != null
                && OwningGrid.DataConnection != null
                && OwningGrid.DataConnection.AllowSort)
            {
                var sort = OwningColumn.GetSortDescription();
                if(sort != null)
                {
                    CurrentSortingState = sort.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending;
                }
            }
            PseudoClasses.Set(":sortascending", 
                CurrentSortingState.HasValue && CurrentSortingState.Value == ListSortDirection.Ascending);
            PseudoClasses.Set(":sortdescending", 
                CurrentSortingState.HasValue && CurrentSortingState.Value == ListSortDirection.Descending);
        }
Пример #2
0
 internal void UpdatePseudoClasses()
 {
     CurrentSortingState = null;
     if (OwningGrid != null &&
         OwningGrid.DataConnection != null &&
         OwningGrid.DataConnection.AllowSort)
     {
         var sort = OwningColumn.GetSortDescription();
         if (sort != null)
         {
             CurrentSortingState = sort.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending;
         }
     }
     PseudoClasses.Set(":sortascending",
                       CurrentSortingState.HasValue && CurrentSortingState.Value == ListSortDirection.Ascending);
     PseudoClasses.Set(":sortdescending",
                       CurrentSortingState.HasValue && CurrentSortingState.Value == ListSortDirection.Descending);
 }
Пример #3
0
        //TODO GroupSorting
        internal void ProcessSort(KeyModifiers keyModifiers)
        {
            // if we can sort:
            //  - DataConnection.AllowSort is true, and
            //  - AllowUserToSortColumns and CanSort are true, and
            //  - OwningColumn is bound, and
            //  - SortDescriptionsCollection exists, and
            //  - the column's data type is comparable
            // then try to sort
            if (OwningColumn != null &&
                OwningGrid != null &&
                OwningGrid.EditingRow == null &&
                OwningColumn != OwningGrid.ColumnsInternal.FillerColumn &&
                OwningGrid.DataConnection.AllowSort &&
                OwningGrid.CanUserSortColumns &&
                OwningColumn.CanUserSort &&
                OwningGrid.DataConnection.SortDescriptions != null)
            {
                DataGrid owningGrid = OwningGrid;

                DataGridSortDescription newSort;

                KeyboardHelper.GetMetaKeyState(keyModifiers, out bool ctrl, out bool shift);

                DataGridSortDescription sort           = OwningColumn.GetSortDescription();
                IDataGridCollectionView collectionView = owningGrid.DataConnection.CollectionView;
                Debug.Assert(collectionView != null);
                using (collectionView.DeferRefresh())
                {
                    // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                    if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                    {
                        owningGrid.DataConnection.SortDescriptions.Clear();
                    }

                    // if ctrl is held down, we only clear the sort directions
                    if (!ctrl)
                    {
                        if (sort != null)
                        {
                            newSort = sort.SwitchSortDirection();

                            // changing direction should not affect sort order, so we replace this column's
                            // sort description instead of just adding it to the end of the collection
                            int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort);
                            if (oldIndex >= 0)
                            {
                                owningGrid.DataConnection.SortDescriptions.Remove(sort);
                                owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                            }
                            else
                            {
                                owningGrid.DataConnection.SortDescriptions.Add(newSort);
                            }
                        }
                        else
                        {
                            string propertyName = OwningColumn.GetSortPropertyName();
                            // no-opt if we couldn't find a property to sort on
                            if (string.IsNullOrEmpty(propertyName))
                            {
                                return;
                            }

                            newSort = DataGridSortDescription.FromPath(propertyName, culture: collectionView.Culture);
                            owningGrid.DataConnection.SortDescriptions.Add(newSort);
                        }
                    }
                }
            }
        }
Пример #4
0
        //TODO GroupSorting
        internal void ProcessSort(InputModifiers inputModifiers)
        {
            // if we can sort:
            //  - DataConnection.AllowSort is true, and
            //  - AllowUserToSortColumns and CanSort are true, and
            //  - OwningColumn is bound, and
            //  - SortDescriptionsCollection exists, and
            //  - the column's data type is comparable
            // then try to sort
            if (OwningColumn != null
                && OwningGrid != null
                && OwningGrid.EditingRow == null
                && OwningColumn != OwningGrid.ColumnsInternal.FillerColumn
                && OwningGrid.DataConnection.AllowSort
                && OwningGrid.CanUserSortColumns
                && OwningColumn.CanUserSort
                && OwningGrid.DataConnection.SortDescriptions != null)
            {
                DataGrid owningGrid = OwningGrid;
                bool desending;
                AvaloniaSortDescription newSort;

                KeyboardHelper.GetMetaKeyState(inputModifiers, out bool ctrl, out bool shift);

                AvaloniaSortDescription sort = OwningColumn.GetSortDescription();
                ICollectionView collectionView = owningGrid.DataConnection.CollectionView;
                Debug.Assert(collectionView != null);
                using (collectionView.DeferRefresh())
                {
                    // if shift is held down, we multi-sort, therefore if it isn't, we'll clear the sorts beforehand
                    if (!shift || owningGrid.DataConnection.SortDescriptions.Count == 0)
                    {
                        /*if (collectionView.CanGroup && collectionView.GroupDescriptions != null)
                        {
                            // Make sure we sort by the GroupDescriptions first
                            for (int i = 0; i < collectionView.GroupDescriptions.Count; i++)
                            {
                                PropertyGroupDescription groupDescription = collectionView.GroupDescriptions[i] as PropertyGroupDescription;
                                if (groupDescription != null && collectionView.SortDescriptions.Count <= i || collectionView.SortDescriptions[i].PropertyName != groupDescription.PropertyName)
                                {
                                    collectionView.SortDescriptions.Insert(Math.Min(i, collectionView.SortDescriptions.Count), new SortDescription(groupDescription.PropertyName, ListSortDirection.Ascending));
                                }
                            }
                            while (collectionView.SortDescriptions.Count > collectionView.GroupDescriptions.Count)
                            {
                                collectionView.SortDescriptions.RemoveAt(collectionView.GroupDescriptions.Count);
                            }
                        }
                        else if (!shift)
                        {
                            owningGrid.DataConnection.SortDescriptions.Clear();
                        }*/
                        owningGrid.DataConnection.SortDescriptions.Clear();
                    }

                    if (sort != null)
                    {
                        newSort = sort.SwitchSortDirection();

                        // changing direction should not affect sort order, so we replace this column's
                        // sort description instead of just adding it to the end of the collection
                        int oldIndex = owningGrid.DataConnection.SortDescriptions.IndexOf(sort);
                        if (oldIndex >= 0)
                        {
                            owningGrid.DataConnection.SortDescriptions.Remove(sort);
                            owningGrid.DataConnection.SortDescriptions.Insert(oldIndex, newSort);
                        }
                        else
                        {
                            owningGrid.DataConnection.SortDescriptions.Add(newSort);
                        }
                    }
                    else
                    {
                        string propertyName = OwningColumn.GetSortPropertyName();
                        // no-opt if we couldn't find a property to sort on
                        if (string.IsNullOrEmpty(propertyName))
                        {
                            return;
                        }

                        newSort = AvaloniaSortDescription.FromPath(propertyName, culture: collectionView.Culture);
                        owningGrid.DataConnection.SortDescriptions.Add(newSort);
                    }
                }

                // We've completed the sort, so send the Invoked event for the column header's automation peer
                /*if (AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked))
                {
                    AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this);
                    if (peer != null)
                    {
                        peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
                    }
                }*/

            }
        }