c# - How can I sort ObservableCollection<T> such that my UI also sees the process of sorting? -


i have listbox item panel set wrappanel. want whenever new item added listbox collection should sorted , process should visible on ui. mean user should able see fancy effect them identify item being sorted. looked @ few posts on stackoverflow , suggest use collectionviewsource. itemsource bound observablecollection in viewmodel.

first wrote code. works new collection bound can't see fancy effect items in container move new position original position :-

 var photolist = photostoupload.tolist<photo>();             photolist.sort(new photosorter());             photostoupload = new observablecollection<photo>(photolist); 

this class :-

 public class photosorter : icomparer<photo>     {          public int compare(photo x, photo y)         {             return x.photobytearr.length - x.photobytearr.length;         }     } 

then wrote simple bubble sorting algorithm. achives desired effect don't know why takes long time. know it's ineffecient algorithm can think of still sorting 10 items shouldn't take more second. here takes 4-5 seconds.

for (int = 0; < photostoupload.count; i++)             {                 (int j = 0; j < photostoupload.count - 1 - i; j++)                 {                     if (photostoupload[j].photobytearr.length > photostoupload[j + 1].photobytearr.length)                     {                         photo photo = photostoupload[j];                         photostoupload[j] = photostoupload[j + 1];                         photostoupload[j + 1] = photo;                     }                 }             } 

can tell me what's best can @ point of time? , why bubble sorting taking long 10 items?

to check changes, use collectionchanged event.

you have error in comparer:

return x.photobytearr.length - y.photobytearr.length; 

btw. code executes instantly me... maybe problem in photo class? or binding/events?

is photo.photobytearr calculated value?


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -