Example #1
0
        // update the weapon count, refresh the datagrid, and re-sort
        public void Update()
        {
            indexCount         = weaponlistLoader.Count();
            tbWeaponCount.Text = indexCount.ToString();

            dgWeaponList.Items.Refresh();

            // after updating the collection, remove all SortDescription and add'em back.
            // this ensures the datagrid is properly updated when already sorted
            SortDescriptionCollection sortDescriptions = new SortDescriptionCollection();

            foreach (SortDescription sd in dgWeaponList.Items.SortDescriptions)
            {
                sortDescriptions.Add(sd);
            }
            dgWeaponList.Items.SortDescriptions.Clear();

            foreach (SortDescription sd in sortDescriptions)
            {
                dgWeaponList.Items.SortDescriptions.Add(sd);
            }

            // update the group by category
            ICollectionView view = CollectionViewSource.GetDefaultView(dgWeaponList.ItemsSource);

            if (view != null && view.CanGroup == true)
            {
                view.GroupDescriptions.Clear();
                view.GroupDescriptions.Add(new PropertyGroupDescription("eCategory"));
            }
        }
        public IList <IReviewEditViewModel> LoadRange(int startIndex, int count, SortDescriptionCollection sortDescriptions, out int overallCount)
        {
            var retVal = new List <IReviewEditViewModel>();
            var sortBy = sortDescriptions.ToDictionary(sortDesc => sortDesc.PropertyName, sortDesc => (sortDesc.Direction == ListSortDirection.Ascending ? "ASC" : "DESC"));

            if (!(SearchFilterReviewType is vm.ReviewType))
            {
                overallCount  = AddReviews(retVal, startIndex, count);
                overallCount += AddComments(retVal, startIndex, count);
            }
            else if (SearchFilterReviewType is vm.ReviewType && (vm.ReviewType)SearchFilterReviewType == vm.ReviewType.Review)
            {
                overallCount = AddReviews(retVal, startIndex, count);
            }
            else if (SearchFilterReviewType is vm.ReviewType && (vm.ReviewType)SearchFilterReviewType == vm.ReviewType.Comment)
            {
                overallCount = AddComments(retVal, startIndex, count);
            }
            else
            {
                overallCount = 0;
            }

            //set SetAll status to false
            SetAll = false;
            _repository.UnitOfWork.CommitAndRefreshChanges();
            return(retVal);
        }
Example #3
0
        public ODataVirtualDataSourceDataProviderWorker(ODataVirtualDataSourceDataProviderWorkerSettings settings)
            : base(settings)
        {
            _baseUri           = settings.BaseUri;
            _entitySet         = settings.EntitySet;
            _sortDescriptions  = settings.SortDescriptions;
            _filterExpressions = settings.FilterExpressions;
            _desiredPropeties  = settings.PropertiesRequested;
            _groupDescriptions = settings.GroupDescriptions;
            if (_groupDescriptions != null && _groupDescriptions.Count > 0)
            {
                _sortDescriptions = new SortDescriptionCollection();
                foreach (var sd in settings.SortDescriptions)
                {
                    _sortDescriptions.Add(sd);
                }

                for (var i = 0; i < _groupDescriptions.Count; i++)
                {
                    _sortDescriptions.Insert(i, _groupDescriptions[i]);
                }
            }
            _isAggregationSupportedByServer = settings.IsAggregationSupportedByServer;
            Task.Factory.StartNew(() => DoWork(), TaskCreationOptions.LongRunning);
        }
Example #4
0
        /// <summary>
        /// 点击listview列进行排序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView_Click_1(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is GridViewColumnHeader)
            {
                //获得点击的列
                GridViewColumn clickedColumn = (e.OriginalSource as GridViewColumnHeader).Column;
                if (clickedColumn != null)
                {
                    //Get binding property of clicked column
                    string bidingProperty = (clickedColumn.DisplayMemberBinding as Binding).Path.Path;

                    //获得listview项是如何排序的
                    SortDescriptionCollection sdc = this.listView.Items.SortDescriptions;

                    //按升序进行排序
                    ListSortDirection sortDirection = ListSortDirection.Ascending;
                    if (sdc.Count > 0)
                    {
                        SortDescription sd = sdc[0];
                        sortDirection = (ListSortDirection)(((-(int)sd.Direction) + 1) % 2);//((((int)sd.Direction) + 1) % 2),原实例没有-号
                        sdc.Clear();
                    }
                    sdc.Add(new SortDescription(bidingProperty, sortDirection));
                }
            }
        }
        public IList <IRmaViewModel> LoadRange(int startIndex, int count, SortDescriptionCollection sortDescriptions, out int overallCount)
        {
            var retVal = new List <IRmaViewModel>();

            using (var repository = _orderRepositoryFactory.GetRepositoryInstance())
            {
                var query = repository.RmaRequests.Expand("RmaReturnItems/RmaLineItems/LineItem,Order");
                //.Where(rma => rma.RmaReturnItems.Any(item => item.ItemState == "AwaitingReturn"));// == Enum.GetName(typeof(RmaRequestStatus), RmaRequestStatus.AwaitingStockReturn));

                if (!string.IsNullOrEmpty(SearchFilterAuthorizationCode))
                {
                    query = query.Where(x => x.AuthorizationCode.Contains(SearchFilterAuthorizationCode));
                }

                if (!string.IsNullOrEmpty(SearchFilterItemName))
                {
                    query =
                        query.Where(
                            x =>
                            x.RmaReturnItems.Any(
                                rItem => rItem.RmaLineItems.Any(lItem => lItem.LineItem.DisplayName.Contains(SearchFilterItemName))));
                }

                if (SearchFilterStatus is RmaRequestStatus)
                {
                    query = query.Where(x => x.Status == Enum.GetName(typeof(RmaRequestStatus), SearchFilterStatus));
                }

                if (!string.IsNullOrEmpty(SearchFilterCustomerName))
                {
                    query = query.Where(x => x.Order.CustomerName.Contains(SearchFilterCustomerName));
                }

                if (!string.IsNullOrEmpty(SearchFilterOrderTrackingNumber))
                {
                    query = query.Where(x => x.Order.TrackingNumber.Contains(SearchFilterOrderTrackingNumber));
                }

                if (!string.IsNullOrEmpty(SearchFilterItemCode))
                {
                    query =
                        query.Where(
                            x =>
                            x.RmaReturnItems.Any(
                                rItem => rItem.RmaLineItems.Any(lItem => lItem.LineItem.CatalogItemCode.Contains(SearchFilterItemCode))));
                }

                if (!string.IsNullOrEmpty(SearchFilterReason) &&
                    AvailableReasons.Any(reason => string.Equals(SearchFilterReason, reason)))
                {
                    query = query.Where(x => x.RmaReturnItems.Any(item => item.ReturnReason == SearchFilterReason));
                }

                overallCount = query.Count();
                var l = query.OrderByDescending(x => x.Created).Skip(startIndex).Take(count).ToList();

                retVal.AddRange(l.Select(i => _rmaVmFactory.GetViewModelInstance(new KeyValuePair <string, object>("item", i))));
            }
            return(retVal);
        }
        // Token: 0x060075B3 RID: 30131 RVA: 0x00219A70 File Offset: 0x00217C70
        internal int CompareLiveShapingItems(LiveShapingItem x, LiveShapingItem y)
        {
            if (x == y || ItemsControl.EqualsEx(x.Item, y.Item))
            {
                return(0);
            }
            int num = 0;

            if (!this._isCustomSorting)
            {
                SortFieldComparer         sortFieldComparer = this._comparer as SortFieldComparer;
                SortDescriptionCollection sortDescriptions  = ((ICollectionView)this.View).SortDescriptions;
                int num2 = this._compInfos.Length;
                for (int i = 0; i < num2; i++)
                {
                    object value  = x.GetValue(this._compInfos[i].Path, this._compInfos[i].Property);
                    object value2 = y.GetValue(this._compInfos[i].Path, this._compInfos[i].Property);
                    num = sortFieldComparer.BaseComparer.Compare(value, value2);
                    if (sortDescriptions[i].Direction == ListSortDirection.Descending)
                    {
                        num = -num;
                    }
                    if (num != 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                num = this._comparer.Compare(x.Item, y.Item);
            }
            return(num);
        }
Example #7
0
        // Private Methods
        private SortPropertyInfo[] CreatePropertyInfo(SortDescriptionCollection sortFields)
        {
            SortPropertyInfo[] fields = new SortPropertyInfo[sortFields.Count];
            for (int k = 0; k < sortFields.Count; ++k)
            {
                PropertyPath pp;
                if (String.IsNullOrEmpty(sortFields[k].PropertyName))
                {
                    // sort by the object itself (as opposed to a property)
                    pp = null;
                }
                else
                {
                    // sort by the value of a property path, to be applied to
                    // the items in the list
                    pp = new PropertyPath(sortFields[k].PropertyName);
                }

                // remember PropertyPath and direction, used when actually sorting
                fields[k].index      = k;
                fields[k].info       = pp;
                fields[k].descending = (sortFields[k].Direction == ListSortDirection.Descending);
            }
            return(fields);
        }
Example #8
0
        private void AddSortRule()
        {
            SortDescriptionCollection sdc = ReportListBox.Items.SortDescriptions;

            //SortDescriptionCollection sdc = new SortDescriptionCollection();

            /*if (sdc.Count > 0)
             * {
             *  SortDescription sd = sdc[0];
             *  sortDirection = (ListSortDirection)((((int)sd.Direction) + 1) % 2);
             *  //判断此列当前的排序方式:升序0,倒序1,并取反进行排序。
             *  sdc.Clear();
             * }*/
            sdc.Clear();
            sdc.Add(new SortDescription("ShiftWork", ListSortDirection.Ascending));
            sdc.Add(new SortDescription("Area", ListSortDirection.Ascending));
            sdc.Add(new SortDescription("BedId", ListSortDirection.Ascending));
            sdc.Add(new SortDescription("PatientName", ListSortDirection.Ascending));
            sdc.Add(new SortDescription("Method", ListSortDirection.Ascending));

            var sdc1 = PatientGroupComboBox.Items.SortDescriptions;

            sdc1.Clear();
            sdc1.Add(new SortDescription("", ListSortDirection.Ascending));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SortCollectionManager"/> class.
        /// </summary>
        /// <param name="sourceCollection">The collection of <see cref="SortDescriptor"/>s to manage</param>
        /// <param name="descriptionCollection">The collection of <see cref="SortDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param>
        /// <param name="expressionCache">The cache with entries for the <see cref="SortDescriptor"/>s</param>
        /// <param name="validationAction">The callback for validating items that are added or changed</param>
        public SortCollectionManager(SortDescriptorCollection sourceCollection, SortDescriptionCollection descriptionCollection, ExpressionCache expressionCache, Action<SortDescriptor> validationAction)
        {
            if (sourceCollection == null)
            {
                throw new ArgumentNullException("sourceCollection");
            }
            if (descriptionCollection == null)
            {
                throw new ArgumentNullException("descriptionCollection");
            }
            if (expressionCache == null)
            {
                throw new ArgumentNullException("expressionCache");
            }
            if (validationAction == null)
            {
                throw new ArgumentNullException("validationAction");
            }

            this._sourceCollection = sourceCollection;
            this._descriptionCollection = descriptionCollection;
            this.ExpressionCache = expressionCache;
            this.ValidationAction = (item) => validationAction((SortDescriptor)item);
            this.AsINotifyPropertyChangedFunc = (item) => ((SortDescriptor)item).Notifier;

            ((INotifyCollectionChanged)descriptionCollection).CollectionChanged += this.HandleDescriptionCollectionChanged;

            this.AddCollection(sourceCollection);
        }
Example #10
0
        private static SortPropertyInfo[] CreatePropertyInfo(SortDescriptionCollection sortFields)
        {
            SortPropertyInfo[] fields = new SortPropertyInfo[sortFields.Count];
            for (int k = 0; k < sortFields.Count; ++k)
            {
                IComparer propertyComparer;
                if (String.IsNullOrEmpty(sortFields[k].PropertyName))
                {
                    // sort by the object itself (as opposed to a property) with a default comparer
                    propertyComparer = Comparer <T> .Default;
                }
                else
                {
                    // sort by the value of a property path, to be applied to
                    // the items in the list
                    Type propertyType = typeof(T).GetNestedPropertyType(sortFields[k].PropertyName);
                    if (propertyType == null)
                    {
                        throw CollectionViewError.ListCollectionView.InvalidPropertyName(sortFields[k].PropertyName);
                    }

                    //dynamically create comparer for property type
                    Type comparerType = typeof(Comparer <>).MakeGenericType(new Type[] { propertyType });
                    propertyComparer = (IComparer)comparerType.GetProperty("Default").GetValue(null, null);
                }

                // remember PropertyPath and direction, used when actually sorting
                fields[k].propertyPath = sortFields[k].PropertyName;
                fields[k].descending   = (sortFields[k].Direction == ListSortDirection.Descending);
                fields[k].comparer     = propertyComparer;
            }
            return(fields);
        }
 public CollectionViewSource()
 {
     this.sort = new SortDescriptionCollection();
     this.sort.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnForwardedCollectionChanged);
     this.groupBy = new ObservableCollection <GroupDescription>();
     this.groupBy.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnForwardedCollectionChanged);
 }
Example #12
0
        private void PrepareColumn(GridViewColumn column)
        {
            if (column.Header is GridViewColumnHeader header)
            {
                header.Click += (_, __) =>
                {
                    string sortBy = header.Tag as string;

                    ICollectionView           dataView         = CollectionViewSource.GetDefaultView(Parent.Items);
                    SortDescriptionCollection sortDescriptions = dataView.SortDescriptions;

                    if (CurrentOrganizedHeader != null)
                    {
                        AdornerLayer.GetAdornerLayer(CurrentOrganizedHeader).Remove(CurrentAdorner);
                        sortDescriptions.Clear();
                    }

                    ListSortDirection newDir = ListSortDirection.Ascending;
                    if (CurrentOrganizedHeader == header && CurrentAdorner.Direction == newDir)
                    {
                        newDir = ListSortDirection.Descending;
                    }

                    CurrentOrganizedHeader = header;
                    CurrentAdorner         = new SortAdorner(header, newDir);
                    AdornerLayer.GetAdornerLayer(header).Add(CurrentAdorner);
                    sortDescriptions.Add(new SortDescription(sortBy, newDir));
                }
            }
            ;
        }
    }
Example #13
0
        public IList <IPriceListViewModel> LoadRange(int startIndex, int count, SortDescriptionCollection sortDescriptions, out int overallCount)
        {
            var retVal = new List <IPriceListViewModel>();

            using (var repository = _pricelistRepository.GetRepositoryInstance())
            {
                var query = repository.Pricelists;

                if (!string.IsNullOrEmpty(SearchFilterKeyword))
                {
                    query = query.Where(x => x.Name.Contains(SearchFilterKeyword) ||
                                        x.Description.Contains(SearchFilterKeyword));
                }
                else
                {
                    if (!string.IsNullOrEmpty(SearchFilterName))
                    {
                        query = query.Where(x => x.Name.Contains(SearchFilterName));
                    }

                    if (!string.IsNullOrEmpty(SearchFilterCurrency))
                    {
                        query = query.Where(x => x.Currency.Contains(SearchFilterCurrency));
                    }
                }

                overallCount = query.Count();
                var items = query.OrderBy(x => x.Name).Skip(startIndex).Take(count).ToList();

                retVal.AddRange(items.Select(item => _itemVmFactory.GetViewModelInstance(new KeyValuePair <string, object>("item", item))));
            }
            return(retVal);
        }
Example #14
0
 private void lvServices_GridViewColumnHeader_Click(object sender, RoutedEventArgs e)//sort
 {
     //ref:WPF中对ListView排序
     //http://www.cnblogs.com/huihui0630/archive/2008/10/22/1317140.html
     if (e.OriginalSource is GridViewColumnHeader)
     {
         //Get clicked column
         GridViewColumn clickedColumn = (e.OriginalSource as GridViewColumnHeader).Column;
         if (clickedColumn != null)
         {
             string bindingProperty;
             //Get binding property of clicked column
             if (clickedColumn.DisplayMemberBinding is System.Windows.Data.Binding)
             {
                 bindingProperty = (clickedColumn.DisplayMemberBinding as System.Windows.Data.Binding).Path.Path;
             }
             else//multibinding for Output Tile Count column
             {
                 System.Windows.Data.Binding binding = (clickedColumn.DisplayMemberBinding as System.Windows.Data.MultiBinding).Bindings[0] as System.Windows.Data.Binding;
                 bindingProperty = binding.Path.Path;
             }
             SortDescriptionCollection sdc           = lvServices.Items.SortDescriptions;
             ListSortDirection         sortDirection = ListSortDirection.Ascending;
             if (sdc.Count > 0)
             {
                 SortDescription sd = sdc[0];
                 sortDirection = (ListSortDirection)((((int)sd.Direction) + 1) % 2);
                 sdc.Clear();
             }
             sdc.Add(new SortDescription(bindingProperty, sortDirection));
         }
     }
 }
 private void OnResortCallback(SortDescriptionCollection sortDescriptions, ColumnCollection columns)
 {
     using (var synchronizationContext = this.StartSynchronizing(this.SortDescriptionsSyncContext))
     {
         this.SynchronizeColumnSort(synchronizationContext, sortDescriptions, columns);
     }
 }
        public SearchServerLibraryItemViewModel(ServerLibraryViewModel library, ArmaServerFilter serverFilter,
                                                SortDescriptionCollection existing = null,
                                                string icon     = null, ServerLibraryGroupViewModel @group = null,
                                                bool isFeatured = false, bool doGrouping = false)
            : base(library, serverFilter, existing, icon, @group, isFeatured, doGrouping)
        {
            Model      = new BuiltInServerContainer("Search");
            Icon       = SixIconFont.withSIX_icon_Search;
            IsFeatured = true;

            SetupFilterChanged();

            UiHelper.TryOnUiThread(() => {
                Items.EnableCollectionSynchronization(ItemsLock);
                _itemsView =
                    Items.CreateCollectionView(
                        new[] {
                    new SortDescription("SearchScore", ListSortDirection.Descending)
                },
                        null, null, Filter.Handler, true);
            });
            var sortDatas = new[] {
                new SortData {
                    DisplayName   = "Search score",
                    Value         = "SearchScore",
                    SortDirection = ListSortDirection.Descending
                }
            };

            Sort = new SortViewModel(ItemsView, sortDatas.Concat(ServersViewModel.Columns).ToArray(), null,
                                     ServersViewModel.RequiredColumns);
            SetupGrouping();
            SortOrder = 3;
            IsRoot    = true;
        }
Example #17
0
        private void SaveTableSortOrder()
        {
            if (_itemList == null)
            {
                return;
            }
            if (_itemList.SortDescriptions.Count <= 0)
            {
                return;
            }

            if (_sortDescriptionCollection == null)
            {
                _sortDescriptionCollection = new SortDescriptionCollection();
            }

            var sortDescriptionArray = new SortDescription[_itemList.SortDescriptions.Count];

            _itemList.SortDescriptions.CopyTo(sortDescriptionArray, 0);

            _sortDescriptionCollection.Clear();
            foreach (var sortDescription in sortDescriptionArray)
            {
                _sortDescriptionCollection.Add(sortDescription);
            }
        }
        public IList <Category> LoadRange(int startIndex, int count, SortDescriptionCollection sortDescriptions, out int overallCount)
        {
            var retVal = new List <Category>();

            using (var repository = _repositoryFactory.GetRepositoryInstance())
            {
                var query = repository.Categories.Expand("Catalog").OfType <Category>();

                if (!String.IsNullOrEmpty(SearchName))
                {
                    query = query.Where(x => x.Name.Contains(SearchName));
                }

                if (!String.IsNullOrEmpty(SearchCode))
                {
                    query = query.Where(x => x.Code.Contains(SearchCode));
                }

                if (!String.IsNullOrEmpty(SearchCatalogId))
                {
                    query = query.Where(x => x.CatalogId == SearchCatalogId);
                }
                else if (SearchModifier.HasFlag(SearchCategoryModifier.RealCatalogsOnly))
                {
                    query = query.Where(x => x.Catalog is catalogModel.Catalog);
                }

                overallCount = query.Count();
                var results = query.OrderBy(x => x.CatalogId).Skip(startIndex).Take(count);
                retVal.AddRange(results);
            }
            return(retVal);
        }
Example #19
0
        private static IDisposable DeferResortHelper(
            IEnumerable itemsSourceCollection,
            CollectionView collectionView,
            SortDescriptionCollection sortDescriptions)
        {
            IDisposable resortDisposable = null;
            DataGridSortDescriptionCollection dataGridSortDescriptions = sortDescriptions as DataGridSortDescriptionCollection;

            if (dataGridSortDescriptions != null)
            {
                // We are in a detail
                resortDisposable = dataGridSortDescriptions.DeferResort();
            }
            else
            {
                Debug.Assert(collectionView != null, "We must have a CollectionView when we are not processing a Detail");

                DataGridCollectionViewBase dataGridCollectionView = itemsSourceCollection as DataGridCollectionViewBase;

                if (dataGridCollectionView != null)
                {
                    resortDisposable = dataGridCollectionView.DataGridSortDescriptions.DeferResort();
                }
                else
                {
                    resortDisposable = collectionView.DeferRefresh();
                }
            }
            Debug.Assert(resortDisposable != null);

            return(resortDisposable);
        }
Example #20
0
 public CollectionViewSource()
 {
     this.sort = new SortDescriptionCollection();
     this.sort.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnForwardedCollectionChanged);
     this.groupBy = new ObservableCollection<GroupDescription>();
     this.groupBy.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnForwardedCollectionChanged);
 }
Example #21
0
        private static void SynchronizeSortIndexes(SortDescriptionCollection sortDescriptions, ColumnCollection columns)
        {
            SortDescription         sortDescription;
            Collection <ColumnBase> handledColumns = new Collection <ColumnBase>();

            for (int i = sortDescriptions.Count - 1; i >= 0; i--)
            {
                sortDescription = sortDescriptions[i];

                foreach (ColumnBase column in columns)
                {
                    string fieldName = column.FieldName;

                    if (fieldName == sortDescription.PropertyName)
                    {
                        column.SetSortIndex(i);
                        handledColumns.Add(column);
                        break;
                    }
                }
            }

            foreach (ColumnBase column in columns)
            {
                if (!handledColumns.Contains(column))
                {
                    column.SetSortIndex(-1);
                    column.SetSortDirection(SortDirection.None);
                }
            }
        }
Example #22
0
        public static void ColumnSort_Click(object sender, RoutedEventArgs e)
        {
            if (!(e.OriginalSource is GridViewColumnHeader))
            {
                return;
            }

            GridViewColumn clickedColumn = (e.OriginalSource as GridViewColumnHeader).Column;   //得到单击的列

            if (clickedColumn != null)
            {
                string bindingProperty = (clickedColumn.DisplayMemberBinding as Binding).Path.Path; //得到单击列所绑定的属性

                SortDescriptionCollection sdc           = ((ListView)sender).Items.SortDescriptions;
                ListSortDirection         sortDirection = ListSortDirection.Ascending;
                if (sdc.Count > 0)
                {
                    SortDescription sd = sdc[0];
                    sortDirection = (ListSortDirection)((((int)sd.Direction) + 1) % 2);  //判断此列当前的排序方式:升序0,倒序1,并取反进行排序。
                    sdc.Clear();
                }

                sdc.Add(new SortDescription(bindingProperty, sortDirection));
            }
        }
Example #23
0
        public SQLiteVirtualDataSourceDataProviderWorker(SQLiteVirtualDataSourceDataProviderWorkerSettings settings)
            : base(settings)
        {
            _tableExpression          = settings.TableExpression;
            _projectionType           = settings.ProjectionType;
            _selectExpressionOverride = settings.SelectExpressionOverride;
            _connection        = settings.Connection;
            _sortDescriptions  = settings.SortDescriptions;
            _groupDescriptions = settings.GroupDescriptions;
            _groupingField     = settings.GroupingColumn;

            if (_groupDescriptions != null && _groupDescriptions.Count > 0)
            {
                _sortDescriptions = new SortDescriptionCollection();
                foreach (var sd in settings.SortDescriptions)
                {
                    _sortDescriptions.Add(sd);
                }

                for (var i = 0; i < _groupDescriptions.Count; i++)
                {
                    _sortDescriptions.Insert(i, _groupDescriptions[i]);
                }
            }
            _filterExpressions = settings.FilterExpressions;
            _desiredPropeties  = settings.PropertiesRequested;
            _propertyMappings  = ResolvePropertyMappings();
            ActualSchema       = ResolveSchema();
            if (_groupDescriptions != null && _groupDescriptions.Count > 0)
            {
                _groupInformation = ResolveGroupInformation();
            }

            Task.Factory.StartNew(() => DoWork(), TaskCreationOptions.LongRunning);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SortCollectionManager"/> class.
        /// </summary>
        /// <param name="sourceCollection">The collection of <see cref="SortDescriptor"/>s to manage</param>
        /// <param name="descriptionCollection">The collection of <see cref="SortDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param>
        /// <param name="expressionCache">The cache with entries for the <see cref="SortDescriptor"/>s</param>
        /// <param name="validationAction">The callback for validating items that are added or changed</param>
        public SortCollectionManager(SortDescriptorCollection sourceCollection, SortDescriptionCollection descriptionCollection, ExpressionCache expressionCache, Action <SortDescriptor> validationAction)
        {
            if (sourceCollection == null)
            {
                throw new ArgumentNullException("sourceCollection");
            }
            if (descriptionCollection == null)
            {
                throw new ArgumentNullException("descriptionCollection");
            }
            if (expressionCache == null)
            {
                throw new ArgumentNullException("expressionCache");
            }
            if (validationAction == null)
            {
                throw new ArgumentNullException("validationAction");
            }

            this._sourceCollection            = sourceCollection;
            this._descriptionCollection       = descriptionCollection;
            this.ExpressionCache              = expressionCache;
            this.ValidationAction             = (item) => validationAction((SortDescriptor)item);
            this.AsINotifyPropertyChangedFunc = (item) => ((SortDescriptor)item).Notifier;

            ((INotifyCollectionChanged)descriptionCollection).CollectionChanged += this.HandleDescriptionCollectionChanged;

            this.AddCollection(sourceCollection);
        }
Example #25
0
        internal QueryGroupsEventArgs(
            DataGridVirtualizingCollectionView collectionView,
            DataGridVirtualizingCollectionViewGroup parentGroup,
            GroupDescription childGroupDescription)
        {
            m_dataGridVirtualizingCollectionView = collectionView;
            m_readonlyGroupPath         = parentGroup.GroupPath.AsReadOnly();
            m_childGroupDescription     = childGroupDescription;
            this.ChildGroupPropertyName = DataGridCollectionViewBase.GetPropertyNameFromGroupDescription(childGroupDescription);

            m_sortDirection = SortDirection.None;

            SortDescriptionCollection sortDescriptions = m_dataGridVirtualizingCollectionView.SortDescriptions;

            int sortDescriptionCount = (sortDescriptions == null) ? 0 : sortDescriptions.Count;

            for (int i = 0; i < sortDescriptions.Count; i++)
            {
                SortDescription sortDescription = sortDescriptions[i];

                if (string.Equals(sortDescription.PropertyName, this.ChildGroupPropertyName))
                {
                    m_sortDirection = (sortDescription.Direction == ListSortDirection.Ascending) ? SortDirection.Ascending : SortDirection.Descending;
                    break;
                }
            }

            m_childGroupNameCountPairs = new List <GroupNameCountPair>();
        }
        private void ColumnHeader_Click(object sender, RoutedEventArgs e)
        {
            var clickedHeader = e.OriginalSource as GridViewColumnHeader;

            if (clickedHeader != null)
            {
                //Get clicked column
                GridViewColumn clickedColumn = clickedHeader.Column;
                if (clickedColumn != null)
                {
                    var binding = clickedColumn.DisplayMemberBinding as Binding;
                    //Get binding property of clicked column
                    string bindingProperty = binding.Path.Path;

                    var lv = sender as ListView;
                    SortDescriptionCollection sdc           = lv.Items.SortDescriptions;
                    ListSortDirection         sortDirection = ListSortDirection.Ascending;
                    if (sdc.Count > 0)
                    {
                        SortDescription sd = sdc[0];
                        sortDirection = sd.Direction == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending;
                        sdc.Clear();
                    }
                    sdc.Add(new SortDescription(bindingProperty, sortDirection));
                }
            }
        }
 public ODataVirtualDataSourceDataProvider()
 {
     _sortDescriptions = new SortDescriptionCollection();
     _sortDescriptions.CollectionChanged += SortDescriptions_CollectionChanged;
     _filterExpressions = new FilterExpressionCollection();
     _filterExpressions.CollectionChanged += FilterExpressions_CollectionChanged;
 }
Example #28
0
        public IList <AsycudaDocumentItem> LoadRange(int startIndex, int count, SortDescriptionCollection sortDescriptions, out int overallCount)
        {
            try
            {
                if (FilterExpression == "All")
                {
                    FilterExpression = "None";
                }
                if (FilterExpression == null)
                {
                    FilterExpression = "None";
                }
                //FilterExpression = "None";
                using (var ctx = new AsycudaDocumentItemRepository())
                {
                    var r = ctx.LoadRange(startIndex, count, FilterExpression, navExp, IncludesLst);
                    overallCount = r.Result.Item2;

                    return(r.Result.Item1.ToList());
                }
            }
            catch (Exception ex)
            {
                StatusModel.Message(ex.Message);
                overallCount = 0;
                return(new List <AsycudaDocumentItem>());
            }
        }
 /// <summary>
 /// Copies the <paramref name="from"/> collection to the <paramref name="to"/> collection
 /// </summary>
 /// <param name="from">The sort descriptions to copy from</param>
 /// <param name="to">The sort descriptions to copy to</param>
 private static void CopySortDescriptions(SortDescriptionCollection from, SortDescriptionCollection to)
 {
     to.Clear();
     foreach (SortDescription sd in from)
     {
         to.Add(sd);
     }
 }
        //
        //  Constructors
        //

        /// <summary>
        ///     Initializes a new instance of the CollectionViewSource class.
        /// </summary>
        public CollectionViewSource()
        {
            _sort = new SortDescriptionCollection();
            ((INotifyCollectionChanged)_sort).CollectionChanged += new NotifyCollectionChangedEventHandler(OnForwardedCollectionChanged);

            _groupBy = new ObservableCollection<GroupDescription>();
            ((INotifyCollectionChanged)_groupBy).CollectionChanged += new NotifyCollectionChangedEventHandler(OnForwardedCollectionChanged);
        }
 // called by ObjectDataSource - set sort, grouping and filter info before calling load
 internal EntityQueryPagedCollectionView(EntityQuery query, int pageSize, int loadSize, 
   SortDescriptionCollection sortDescriptors, ObservableCollection<GroupDescription> groupDescriptors, IPredicateDescription filter) 
  : this(query, pageSize, loadSize, true, false) {
   sortDescriptors.ForEach(d => SortDescriptions.Add(d));
   groupDescriptors.ForEach(d=> GroupDescriptions.Add(d));
   SetQueryFilter(filter);
   Refresh();
 }
Example #32
0
 public StandardCollectionViewGroup(StandardCollectionViewGroup parent, object name, int depth, bool isBottomLevel, SortDescriptionCollection sorters)
     : base(name)
 {
     this.isBottomLevel = isBottomLevel;
     Depth   = depth;
     Parent  = parent;
     Sorters = sorters;
 }
Example #33
0
		public StandardCollectionViewGroup (StandardCollectionViewGroup parent, object name, int depth, bool isBottomLevel, SortDescriptionCollection sorters)
			: base (name)
		{
			this.isBottomLevel = isBottomLevel;
			Depth = depth;
			Parent = parent;
			Sorters = sorters;
		}
Example #34
0
        //
        //  Constructors
        //

        /// <summary>
        ///     Initializes a new instance of the CollectionViewSource class.
        /// </summary>
        public CollectionViewSource()
        {
            _sort = new SortDescriptionCollection();
            ((INotifyCollectionChanged)_sort).CollectionChanged += new NotifyCollectionChangedEventHandler(OnForwardedCollectionChanged);

            _groupBy = new ObservableCollection <GroupDescription>();
            ((INotifyCollectionChanged)_groupBy).CollectionChanged += new NotifyCollectionChangedEventHandler(OnForwardedCollectionChanged);
        }
 /// <summary>
 /// Resets the <paramref name="sortDescriptors"/> collection to match the <paramref name="sortDescriptions"/> collection.
 /// </summary>
 /// <param name="sortDescriptions">The collection to match</param>
 /// <param name="sortDescriptors">The collection to reset</param>
 private static void ResetToSortDescriptions(SortDescriptionCollection sortDescriptions, SortDescriptorCollection sortDescriptors)
 {
     sortDescriptors.Clear();
     foreach (SortDescription description in sortDescriptions)
     {
         sortDescriptors.Add(SortCollectionManager.GetDescriptorFromDescription(description));
     }
 }
Example #36
0
 public static void Add <T, U>(this SortDescriptionCollection collection, ListSortDirection direction, Expression <Func <T, U> > memberExpression)
 {
     if (TryGetMemberNameFromExpression(memberExpression, out string memberName))
     {
         var sortDesc = new SortDescription(memberName, direction);
         collection.Add(sortDesc);
     }
 }
Example #37
0
        // create a comparer for an Xml collection (if applicable)
        internal static IComparer PrepareXmlComparer(IEnumerable collection, SortDescriptionCollection sort, CultureInfo culture)
        {
            SystemXmlExtensionMethods extensions = AssemblyHelper.ExtensionsForSystemXml();
            if (extensions != null)
            {
                return extensions.PrepareXmlComparer(collection, sort, culture);
            }

            return null;
        }
Example #38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PagingArguments"/> class.
        /// </summary>
        /// <param name="pageIndex">The zero-based index of the requested data page.</param>
        /// <param name="pageSize">The size of the requested data page.</param>
        /// <param name="sortDescriptions">The <see cref="SortDescriptionCollection"/> associated with the request.</param>
        public PagingArguments( int pageIndex, int pageSize, SortDescriptionCollection sortDescriptions )
        {
            Arg.NotNull( sortDescriptions, nameof( sortDescriptions ) );
            Arg.GreaterThanOrEqualTo( pageIndex, 0, nameof( pageIndex ) );
            Arg.GreaterThan( pageSize, 0, nameof( pageSize ) );

            this.pageIndex = pageIndex;
            this.pageSize = pageSize;
            this.sortDescriptions = sortDescriptions;
        }
Example #39
0
        /// <summary> 
        /// Create a comparer, using the SortDescription and a Type; 
        /// tries to find a reflection PropertyInfo for each property name
        /// </summary> 
        /// <param name="sortFields">list of property names and direction to sort by</param>
        /// <param name="culture">culture to use for comparisons</param>
        internal SortFieldComparer(SortDescriptionCollection sortFields, CultureInfo culture)
        { 
            _sortFields = sortFields;
            _fields = CreatePropertyInfo(_sortFields); 
 
            // create the comparer
            _comparer = (culture == null || culture == CultureInfo.InvariantCulture) ? Comparer.DefaultInvariant 
                        : (culture == CultureInfo.CurrentCulture) ? Comparer.Default
                        : new Comparer(culture);
        }
		public void SortDescriptionCollectionAddNoHandlerTest()
		{
			SortDescriptionCollection sdc = new SortDescriptionCollection ();
			SortDescription addedItem = new SortDescription ("A", ListSortDirection.Ascending);

			sdc.Add (addedItem);

			addedItem = sdc[0];

			Assert.AreEqual ("A", addedItem.PropertyName, "ADDN_#1");
			Assert.AreEqual (ListSortDirection.Ascending, addedItem.Direction, "ADDN_#2");
			Assert.AreEqual (true, addedItem.IsSealed, "ADDN_#3");
		}
Example #41
0
        private static void SortDataGrid(DataGrid dataGrid)
        {
            var sortDescriptions = new SortDescriptionCollection();
            foreach (SortDescription sd in dataGrid.Items.SortDescriptions)
            {
                sortDescriptions.Add(sd);
            }
            dataGrid.Items.SortDescriptions.Clear();

            foreach (SortDescription sd in sortDescriptions)
            {
                dataGrid.Items.SortDescriptions.Add(sd);
            }
        }
Example #42
0
        public static int FindSortDescription(SortDescriptionCollection sortDescriptions, string sortPropertyName)
        {
            int index = -1;
            int i = 0;
            foreach (SortDescription sortDesc in sortDescriptions)
            {
                if (System.String.CompareOrdinal(sortDesc.PropertyName, sortPropertyName) == 0)
                {
                    index = i;
                    break;
                }
                i++;
            }

            return index;
        }
 public void Apply(DataGridColumn column, int gridColumnCount, SortDescriptionCollection sortDescriptions)
 {
     column.Width = new DataGridLength(WidthValue, WidthType);
     column.SortDirection = SortDirection;
     if (SortDirection != null)
     {
         sortDescriptions.Add(new SortDescription(PropertyPath, SortDirection.Value));
     }
     if (column.DisplayIndex != DisplayIndex)
     {
         var maxIndex = (gridColumnCount == 0) ? 0 : gridColumnCount - 1;
         column.DisplayIndex = (DisplayIndex <= maxIndex) ? DisplayIndex : maxIndex;
     }
     column.Visibility = IsVisible ? Visibility.Visible : Visibility.Collapsed;
     column.SortMemberPath = SortMemberPath;
 }
		public void SortDescriptionCollectionAddTest()
		{
			SortDescriptionCollection sdc = new SortDescriptionCollection ();
			SortDescription addedItem = new SortDescription ("NONE", ListSortDirection.Ascending);

			((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
				Assert.AreEqual (NotifyCollectionChangedAction.Add, e.Action, "ADD_#0");
				addedItem = (SortDescription)e.NewItems [0];
				Assert.AreEqual (true, addedItem.IsSealed, "ADD_#0b");
			};

			sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));

			Assert.AreEqual ("A", addedItem.PropertyName, "ADD_#1");
			Assert.AreEqual (ListSortDirection.Ascending, addedItem.Direction, "ADD_#2");
			Assert.AreEqual (true, addedItem.IsSealed, "ADD_#3");
		}
    protected void SynchronizeColumnSort(
      SynchronizationContext synchronizationContext,
      SortDescriptionCollection sortDescriptions,
      ColumnCollection columns )
    {
      ColumnSortCommand.ThrowIfNull( synchronizationContext, "synchronizationContext" );
      ColumnSortCommand.ThrowIfNull( sortDescriptions, "sortDescriptions" );
      ColumnSortCommand.ThrowIfNull( columns, "columns" );

      if( !synchronizationContext.Own || !columns.Any() )
        return;

      this.SetResortCallback( sortDescriptions, columns );

      int count = sortDescriptions.Count;
      Dictionary<string, ColumnSortInfo> sortOrder = new Dictionary<string, ColumnSortInfo>( count );

      for( int i = 0; i < count; i++ )
      {
        var sortDescription = sortDescriptions[ i ];
        string propertyName = sortDescription.PropertyName;

        if( sortOrder.ContainsKey( propertyName ) )
          continue;

        sortOrder.Add( propertyName, new ColumnSortInfo( i, sortDescription.Direction ) );
      }

      foreach( var column in columns )
      {
        ColumnSortInfo entry;

        if( sortOrder.TryGetValue( column.FieldName, out entry ) )
        {
          column.SetSortIndex( entry.Index );
          column.SetSortDirection( entry.Direction );
        }
        else
        {
          column.SetSortIndex( -1 );
          column.SetSortDirection( SortDirection.None );
        }
      }
    }
		public void SortDescriptionCollectionRemoveTest()
		{
			SortDescriptionCollection sdc = new SortDescriptionCollection ();
			SortDescription removedItem = new SortDescription ("NONE", ListSortDirection.Ascending);

			sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));

			((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
				Assert.AreEqual (NotifyCollectionChangedAction.Remove, e.Action, "REM_#0");
				removedItem = (SortDescription)e.OldItems [0];
				Assert.AreEqual (true, removedItem.IsSealed, "REM_#0b");
			};

			sdc.RemoveAt (0);

			Assert.AreEqual ("A", removedItem.PropertyName, "REM_#1");
			Assert.AreEqual (ListSortDirection.Ascending, removedItem.Direction, "REM_#2");
			Assert.AreEqual (true, removedItem.IsSealed, "REM_#3");
		}
Example #47
0
        public static DataGridSortDescription SaveSorting(DataGrid grid, ICollectionView view)
        {
            DataGridSortDescription sortDescription = new DataGridSortDescription();

            //Save the current sort order of the columns
            SortDescriptionCollection sortDescriptions = new SortDescriptionCollection();
            if (view != null)
            {
                view.SortDescriptions.ToList().ForEach(sd => sortDescriptions.Add(sd));
            }
            sortDescription.SortDescription = sortDescriptions;

            //save the sort directions (these define the little arrow on the column header...)
            IDictionary<DataGridColumn, ListSortDirection?> sortDirections = new Dictionary<DataGridColumn, ListSortDirection?>();
            foreach (DataGridColumn c in grid.Columns)
            {
                sortDirections.Add(c, c.SortDirection);
            }
            sortDescription.SortDirection = sortDirections;

            return sortDescription;
        }
 public ODataVirtualDataSourceDataProviderWorker(ODataVirtualDataSourceDataProviderWorkerSettings settings)
     :base(settings)
 {
     _baseUri = settings.BaseUri;
     _entitySet = settings.EntitySet;
     _sortDescriptions = settings.SortDescriptions;
     _filterExpressions = settings.FilterExpressions;
     _desiredPropeties = settings.PropertiesRequested;
     Task.Factory.StartNew(() => DoWork(), TaskCreationOptions.LongRunning);
 }        
Example #49
0
        // Private Methods 
        private SortPropertyInfo[] CreatePropertyInfo(SortDescriptionCollection sortFields)
        {
            SortPropertyInfo[] fields = new SortPropertyInfo[sortFields.Count];
            for (int k = 0; k < sortFields.Count; ++k) 
            {
                PropertyPath pp; 
                if (String.IsNullOrEmpty(sortFields[k].PropertyName)) 
                {
                    // sort by the object itself (as opposed to a property) 
                    pp = null;
                }
                else
                { 
                    // sort by the value of a property path, to be applied to
                    // the items in the list 
                    pp = new PropertyPath(sortFields[k].PropertyName); 
                }
 
                // remember PropertyPath and direction, used when actually sorting
                fields[k].index = k;
                fields[k].info = pp;
                fields[k].descending = (sortFields[k].Direction == ListSortDirection.Descending); 
            }
            return fields; 
        } 
 public void Apply(DataGridColumn column, int gridColumnCount, SortDescriptionCollection sortDescriptions) {
     column.Width = new DataGridLength(WidthValue, WidthType);
     column.SortDirection = SortDirection;
     if (SortDirection != null)
         sortDescriptions.Add(new SortDescription(PropertyPath, SortDirection.Value));
     if (column.DisplayIndex != DisplayIndex) {
         var maxIndex = (gridColumnCount == 0) ? 0 : gridColumnCount - 1;
         column.DisplayIndex = (DisplayIndex <= maxIndex) ? DisplayIndex : maxIndex;
     }
 }
    internal static void ToggleColumnSort(
      DataGridContext dataGridContext,
      SortDescriptionCollection sortDescriptions,
      ColumnCollection columns,
      ColumnBase column,
      bool shiftUnpressed )
    {
      if( column == null )
        throw new ArgumentNullException( "column" );

      Debug.Assert( ( dataGridContext != null ) || ( column.ParentDetailConfiguration != null ) );

      if( ( dataGridContext == null ) && ( column.ParentDetailConfiguration == null ) )
        throw new DataGridInternalException( "DataGridContext or ParentDetailConfiguration can't be null." );

      DataGridContext parentDataGridContext = ( dataGridContext == null ) ? null : 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
      HashSet<IDisposable> deferRestoreStateDisposable = new HashSet<IDisposable>();

      if( parentDataGridContext != null )
      {
        foreach( DataGridContext childContext in parentDataGridContext.GetChildContexts() )
        {
          deferRestoreStateDisposable.Add( childContext.DeferRestoreState() );
        }
      }

      IDisposable deferResortHelper = ( dataGridContext == null ) ? null :
        SortingHelper.DeferResortHelper( dataGridContext.ItemsSourceCollection, dataGridContext.Items, sortDescriptions );

      //this will ensure that all DataGridCollectionViews mapped to this SortDescriptions collection will only refresh their sorting once!
      SortDirection newSortDirection = column.SortDirection;
      if( ( shiftUnpressed ) &&
          ( ( column.SortIndex == -1 ) || ( sortDescriptions.Count > 1 ) ) )
        sortDescriptions.Clear();

      switch( newSortDirection )
      {
        case SortDirection.None:
          newSortDirection = SortDirection.Ascending;
          break;
        case SortDirection.Ascending:
          newSortDirection = SortDirection.Descending;
          break;

        case SortDirection.Descending:
          newSortDirection = SortDirection.None;
          break;
      }

      SortingHelper.ApplyColumnSort( dataGridContext, sortDescriptions, columns, column, newSortDirection );

      if( deferResortHelper != null )
      {
        //end of the DeferResort(), any DataGridCollectionView listening to the SortDescriptions instance will refresh its sorting!
        deferResortHelper.Dispose();
      }

      foreach( IDisposable disposable in deferRestoreStateDisposable )
      {
        try
        {
          // Try/Catch to ensure all contexts are restored
          disposable.Dispose();
        }
        catch( Exception )
        {
        }
      }

      deferRestoreStateDisposable.Clear();
    }
Example #52
0
		public CollectionViewSource ()
		{
			CachedViews = new Dictionary<object, ICollectionView> ();
			SortDescriptions = new SortDescriptionCollection ();
			GroupDescriptions = new ObservableCollection<GroupDescription> ();

			GroupDescriptions.CollectionChanged += (o, e) => Refresh ();
			((INotifyCollectionChanged)SortDescriptions).CollectionChanged += (o, e) => Refresh ();
			FilterCallback = (o) => {
				var h = filter;
				if (h != null) {
					var args = new FilterEventArgs (o);
					h (this, args);
					return args.Accepted;
				}
				return true;
			};
		}
		private bool IsSortDifferent(SortDescriptionCollection proposedSorts)
		{
			bool different = false;

			if (proposedSorts == null || this.sortProps == null)
			{
				different = (proposedSorts != this.sortProps);
			}
			else if (proposedSorts.Count == this.sortProps.Count)
			{
				for (int i = 0; i < proposedSorts.Count; i++)
				{
					if (proposedSorts[i].PropertyName != this.sortProps[i].PropertyName ||
						proposedSorts[i].Direction != this.sortProps[i].Direction)
					{
						different = true;
						break;
					}
				}
			}
			else
				different = true;

			return different;
		}
        // set new SortDescription collection; rehook collection change notification handler
        private void SetSortDescriptions(SortDescriptionCollection descriptions)
        {
            if (_sort != null)
            {
                ((INotifyCollectionChanged)_sort).CollectionChanged -= new NotifyCollectionChangedEventHandler(SortDescriptionsChanged);
            }

            _sort = descriptions;

            if (_sort != null)
            {
                Invariant.Assert(_sort.Count == 0, "must be empty SortDescription collection");
                ((INotifyCollectionChanged)_sort).CollectionChanged += new NotifyCollectionChangedEventHandler(SortDescriptionsChanged);
            }
        }
    private IQueryable SortQueryable( IQueryable queryable, bool reverseSort )
    {
      DataGridVirtualizingCollectionViewBase parentCollectionView = this.GetCollectionView();

      Debug.Assert( parentCollectionView != null );

      SortDescriptionCollection explicitSortDescriptions = parentCollectionView.SortDescriptions;

      ListSortDirection directionToUseForImplicitSortDescriptions = ListSortDirection.Ascending;

      if( explicitSortDescriptions.Count > 0 )
        directionToUseForImplicitSortDescriptions = explicitSortDescriptions[ explicitSortDescriptions.Count - 1 ].Direction;

      SortDescriptionCollection implicitSortDescriptions = new SortDescriptionCollection();

      DataGridVirtualizingQueryableCollectionViewGroupRoot groupRoot =
        parentCollectionView.RootGroup as DataGridVirtualizingQueryableCollectionViewGroupRoot;

      Debug.Assert( groupRoot != null );

      string[] primaryKeys = groupRoot.PrimaryKeys;

      if( primaryKeys != null )
      {
        for( int i = 0; i < primaryKeys.Length; i++ )
        {
          string primaryKey = primaryKeys[ i ];

          Debug.Assert( !string.IsNullOrEmpty( primaryKey ) );

          implicitSortDescriptions.Add( new SortDescription( primaryKey, directionToUseForImplicitSortDescriptions ) );
        }
      }

      return queryable.OrderBy( implicitSortDescriptions, explicitSortDescriptions, reverseSort );
    }
 private static SortPropertyInfo[] CreatePropertyInfo(SortDescriptionCollection sortFields)
 {
     SortPropertyInfo[] fields = new SortPropertyInfo[sortFields.Count];
     for (int k = 0; k < sortFields.Count; ++k)
     {
         // remember PropertyPath and Direction, used when actually sorting
         fields[k].PropertyPath = sortFields[k].PropertyName;
         fields[k].Descending = (sortFields[k].Direction == ListSortDirection.Descending);
     }
     return fields;
 }
 // create a comparer for an Xml collection (if applicable)
 internal abstract IComparer PrepareXmlComparer(IEnumerable collection, SortDescriptionCollection sort, CultureInfo culture);
    private static IDisposable DeferResortHelper( 
      IEnumerable itemsSourceCollection, 
      CollectionView collectionView, 
      SortDescriptionCollection sortDescriptions )
    {
      IDisposable resortDisposable = null;
      DataGridSortDescriptionCollection dataGridSortDescriptions = sortDescriptions as DataGridSortDescriptionCollection;

      if( dataGridSortDescriptions != null )
      {
        // We are in a detail
        resortDisposable = dataGridSortDescriptions.DeferResort();
      }
      else
      {
        Debug.Assert( collectionView != null, "We must have a CollectionView when we are not processing a Detail" );

        DataGridCollectionViewBase dataGridCollectionView = itemsSourceCollection as DataGridCollectionViewBase;

        if( dataGridCollectionView != null )
        {
          resortDisposable = dataGridCollectionView.DataGridSortDescriptions.DeferResort();
        }
        else
        {
          resortDisposable = collectionView.DeferRefresh();
        }
      }
      Debug.Assert( resortDisposable != null );

      return resortDisposable;
    }
    private static void SynchronizeSortIndexes( SortDescriptionCollection sortDescriptions, ColumnCollection columns )
    {
      SortDescription sortDescription;
      Collection<ColumnBase> handledColumns = new Collection<ColumnBase>();

      for( int i = sortDescriptions.Count - 1; i >= 0; i-- )
      {
        sortDescription = sortDescriptions[ i ];

        foreach( ColumnBase column in columns )
        {
          string fieldName = column.FieldName;

          if( fieldName == sortDescription.PropertyName )
          {
            column.SetSortIndex( i );
            handledColumns.Add( column );
            break;
          }
        }
      }

      foreach( ColumnBase column in columns )
      {
        if( !handledColumns.Contains( column ) )
        {
          column.SetSortIndex( -1 );
          column.SetSortDirection( SortDirection.None );
        }
      }
    }
    private static void ApplyColumnSort( DataGridContext dataGridContext, SortDescriptionCollection sortDescriptions, ColumnCollection columns, ColumnBase column, SortDirection sortDirection )
    {
      if( column == null )
        throw new ArgumentNullException( "column" );

      Debug.Assert( ( dataGridContext != null ) || ( column.ParentDetailConfiguration != null ) );

      if( ( dataGridContext == null ) && ( column.ParentDetailConfiguration == null ) )
        throw new DataGridInternalException( "DataGridContext or ParentDetailConfiguration cannot be null." );

      if( !columns.Contains( column ) )
        throw new ArgumentException( "The specified column is not part of the DataGridContext.", "column" );

      string fieldName = column.FieldName;

      bool canSort = ( dataGridContext != null ) ? dataGridContext.Items.CanSort : true;

      if( ( !string.IsNullOrEmpty( fieldName ) ) && ( canSort == true ) )
      {
        SortDescription existingSort;
        int sortDescriptionIndex = sortDescriptions.Count;

        for( int i = sortDescriptions.Count - 1; i >= 0; i-- )
        {
          existingSort = sortDescriptions[ i ];

          if( existingSort.PropertyName == fieldName )
          {
            if( ( ( existingSort.Direction == ListSortDirection.Ascending ) && ( sortDirection == SortDirection.Ascending ) ) ||
                ( ( existingSort.Direction == ListSortDirection.Descending ) && ( sortDirection == SortDirection.Descending ) ) )
            {
              // Nothing to change!
              sortDescriptionIndex = -1;
            }
            else
            {
              sortDescriptionIndex = i;
              sortDescriptions.Remove( existingSort );
            }

            break;
          }
        }

        int maxDescriptions = ( dataGridContext != null ) ? dataGridContext.MaxSortLevels 
          : column.ParentDetailConfiguration.MaxSortLevels;

        if( ( maxDescriptions != -1 ) && ( sortDescriptions.Count >= maxDescriptions ) )
        {
          // Cannot insert sort description since it would go beyond the max sort description count.
          sortDescriptionIndex = -1;
          sortDirection = SortDirection.None;
        }

        if( ( sortDescriptionIndex > -1 ) && ( sortDirection != SortDirection.None ) )
        {
          SortDescription sortDescription = new SortDescription( fieldName,
            ( sortDirection == SortDirection.Ascending ) ? ListSortDirection.Ascending : ListSortDirection.Descending );

          sortDescriptions.Insert( sortDescriptionIndex, sortDescription );
          column.SetSortIndex( sortDescriptionIndex );
          column.SetSortDirection( sortDirection );
        }

        SortingHelper.SynchronizeSortIndexes( sortDescriptions, columns );
      }
    }