Пример #1
0
 void ColumnHeader_Click(Object sender, RoutedEventArgs e)
 {
     if (Keyboard.Modifiers == ModifierKeys.Shift)
     {
         this.clearSortDescriptions();
         return;
     }
     //
     GridViewColumnHeader columnHeader1 = e.OriginalSource as GridViewColumnHeader;
     if (columnHeader1 == null) { return; }
     if (columnHeader1.Role != GridViewColumnHeaderRole.Padding)
     {
         string propertyName1 = columnHeader1.Tag as string;
         if (string.IsNullOrEmpty(propertyName1))
         {
             System.Diagnostics.Trace.WriteLine("ERROR: ColumnHeader_Click(): propertyName1 == null");
             return;
         }
         //
         ListSortDirection sortDirection1 = ListSortDirection.Ascending;
         {
             SortDescription sd1;
             if (_sortDescriptionDict.TryGetValue(columnHeader1, out sd1))
             {
                 if (sd1.Direction == ListSortDirection.Ascending)
                 {
                     sortDirection1 = ListSortDirection.Descending;
                 }
             }
         }
         // clear if Not Control key pressed
         if (Keyboard.Modifiers != ModifierKeys.Control)
         {
             this.clearSortDescriptions();
         }
         // SortDescription
         int idx_SortDescription1 = _viewSource.SortDescriptions.Count;
         {
             SortDescription sd1;
             if (_sortDescriptionDict.TryGetValue(columnHeader1, out sd1))
             {
                 idx_SortDescription1 = _viewSource.SortDescriptions.IndexOf(sd1);
                 _viewSource.SortDescriptions.Remove(sd1);
             }
         }
         {
             SortDescription sd2 = new SortDescription(propertyName1, sortDirection1);
             _sortDescriptionDict[columnHeader1] = sd2;
             _viewSource.SortDescriptions.Insert(idx_SortDescription1, sd2);
         }
         // SortAdorner
         {
             SortAdorner sa1;
             if (_sortAdornerDict.TryGetValue(columnHeader1, out sa1))
             {
                 AdornerLayer.GetAdornerLayer(columnHeader1).Remove(sa1);
             }
         }
         {
             SortAdorner sa2 = new SortAdorner(columnHeader1, sortDirection1);
             _sortAdornerDict[columnHeader1] = sa2;
             AdornerLayer.GetAdornerLayer(columnHeader1).Add(sa2);
         }
     }
 }
Пример #2
0
        void ColumnHeader_Click(Object sender, RoutedEventArgs e)
        {
            if (Keyboard.Modifiers == ModifierKeys.Shift)
            {
                this.clearSortDescriptions();
                return;
            }
            //
            GridViewColumnHeader columnHeader1 = e.OriginalSource as GridViewColumnHeader;

            if (columnHeader1 == null)
            {
                return;
            }
            if (columnHeader1.Role != GridViewColumnHeaderRole.Padding)
            {
                string propertyName1 = columnHeader1.Tag as string;
                if (string.IsNullOrEmpty(propertyName1))
                {
                    System.Diagnostics.Trace.WriteLine("ERROR: ColumnHeader_Click(): propertyName1 == null");
                    return;
                }
                //
                ListSortDirection sortDirection1 = ListSortDirection.Ascending;
                {
                    SortDescription sd1;
                    if (_sortDescriptionDict.TryGetValue(columnHeader1, out sd1))
                    {
                        if (sd1.Direction == ListSortDirection.Ascending)
                        {
                            sortDirection1 = ListSortDirection.Descending;
                        }
                    }
                }
                // clear if Not Control key pressed
                if (Keyboard.Modifiers != ModifierKeys.Control)
                {
                    this.clearSortDescriptions();
                }
                // SortDescription
                int idx_SortDescription1 = _viewSource.SortDescriptions.Count;
                {
                    SortDescription sd1;
                    if (_sortDescriptionDict.TryGetValue(columnHeader1, out sd1))
                    {
                        idx_SortDescription1 = _viewSource.SortDescriptions.IndexOf(sd1);
                        _viewSource.SortDescriptions.Remove(sd1);
                    }
                }
                {
                    SortDescription sd2 = new SortDescription(propertyName1, sortDirection1);
                    _sortDescriptionDict[columnHeader1] = sd2;
                    _viewSource.SortDescriptions.Insert(idx_SortDescription1, sd2);
                }
                // SortAdorner
                {
                    SortAdorner sa1;
                    if (_sortAdornerDict.TryGetValue(columnHeader1, out sa1))
                    {
                        AdornerLayer.GetAdornerLayer(columnHeader1).Remove(sa1);
                    }
                }
                {
                    SortAdorner sa2 = new SortAdorner(columnHeader1, sortDirection1);
                    _sortAdornerDict[columnHeader1] = sa2;
                    AdornerLayer.GetAdornerLayer(columnHeader1).Add(sa2);
                }
            }
        }