コード例 #1
0
        private static void OnSortDirectionChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            var grid = sender as ListView;

            if (grid != null)
            {
                SortableGridViewColumn col = GetCurrentSortColumn(grid);
                if (col != null)
                {
                    col.SortDirection = (ColumnSortDirection)args.NewValue;
                }
                Sort(grid);
            }
        }
コード例 #2
0
        private static void Sort(ListView grid)
        {
            ColumnSortDirection    currentDirection = GetSortDirection(grid);
            SortableGridViewColumn column           = GetCurrentSortColumn(grid);

            if (column != null && GetSortMode(grid) == ListViewSortMode.Automatic && currentDirection != ColumnSortDirection.None)
            {
                ICollectionView dataView = CollectionViewSource.GetDefaultView(grid.ItemsSource);

                string sortBy = column.SortBy;
                if (sortBy == null)
                {
                    var binding = column.DisplayMemberBinding as Binding;
                    if (binding != null && binding.Path != null)
                    {
                        sortBy = binding.Path.Path;
                    }
                }

                dataView.SortDescriptions.Clear();
                if (sortBy != null)
                {
                    ListSortDirection direction;
                    if (currentDirection == ColumnSortDirection.Descending)
                    {
                        direction = ListSortDirection.Descending;
                    }
                    else
                    {
                        direction = ListSortDirection.Ascending;
                    }
                    dataView.SortDescriptions.Add(new SortDescription(sortBy, direction));
                }
                dataView.Refresh();
            }
        }
コード例 #3
0
 public static void SetCurrentSortColumn(ListView listView, SortableGridViewColumn value)
 {
     listView.SetValue(CurrentSortColumnProperty, value);
 }