// Sort the data source with a default comparer void Sort(PropertySortDescription operation) { if (VerifyComparable(operation))// if we can't compare data, we don't try to sort { ListSortDirection directionBackup = operation.Direction; operation.Direction = _operations.GetFixedDirection(operation); Collection <object> childItems = new Collection <object>(); //todo: replace with a sort algorithm that is O(NLogN), for example by creating a List<T> and calling List<T>.Sort(comparer). foreach (object item in Items) { int index; // we get the value of the sorting property on this item to allow comparison (if we are here, we know that data is comparable) // then we get the position where we need to insert this item #if OPENSILVER if (true) #elif BRIDGE if (CSHTML5.Interop.IsRunningInTheSimulator) #endif { IComparable value = (IComparable)GetValue(item, operation); index = GetPosIndex_SimulatorOnly(operation, value, 0, childItems.Count, childItems); } else { dynamic value = GetValue(item, operation); index = GetPosIndex_JSOnly(operation, value, 0, childItems.Count, childItems); } childItems.Insert(index, item); } operation.Direction = directionBackup; // Pass the result of the sort to a child CollectionViewGroup in order to apply other operations (such as sort) if any: INTERNAL_CollectionViewGroupInternal newView = new INTERNAL_CollectionViewGroupInternal(childItems, this, _operations); _operations.Requester.AddView(newView); // create child branch after sorting operation } else { INTERNAL_CollectionViewGroupInternal newView = new INTERNAL_CollectionViewGroupInternal(Items, this, _operations); _operations.Requester.AddView(newView); // create child branch without sorting } }