title: How can I sort ObservableCollection<T> such that my UI also sees the process of sorting?
body: <p>I have Listbox whose item panel is set to wrappanel. I want that whenever a new item is added to listbox my collection should be sorted and the process should be visible on the UI. I mean the user should be able to see that fancy effect to help them identify that the item is being sorted. I looked at few posts on stackoverflow and they suggest to use CollectionViewSource. However my itemsource is bound to ObservableCollection in ViewModel.</p>
  
  <p>First I wrote this code. It works however as a new collection is bound I can't see that fancy effect where the items in the container just move to their new position from the original position :-</p>
  
  <pre><code> var photoList = PhotosToUpload.ToList&lt;Photo&gt;();
              photoList.Sort(new PhotoSorter());
              PhotosToUpload = new ObservableCollection&lt;Photo&gt;(photoList);
  </code></pre>
  
  <p>This is my class :-</p>
  
  <pre><code> public class PhotoSorter : IComparer&lt;Photo&gt;
      {
  
          public int Compare(Photo x, Photo y)
          {
              return x.PhotoByteArr.Length - x.PhotoByteArr.Length;
          }
      }
  </code></pre>
  
  <p>Then I wrote a simple bubble sorting algorithm. This achives the desired effect but I don't know why it takes too long time. I know it's the most ineffecient algorithm that anybody can think of but still sorting 10 items shouldn't take more than a second. Here it takes 4-5 seconds.</p>
  
  <pre><code>for (int i = 0; i &lt; PhotosToUpload.Count; i++)
              {
                  for (int j = 0; j &lt; PhotosToUpload.Count - 1 - i; j++)
                  {
                      if (PhotosToUpload[j].PhotoByteArr.Length &gt; PhotosToUpload[j + 1].PhotoByteArr.Length)
                      {
                          Photo photo = PhotosToUpload[j];
                          PhotosToUpload[j] = PhotosToUpload[j + 1];
                          PhotosToUpload[j + 1] = photo;
                      }
                  }
              }
  </code></pre>
  
  <p>Can anybody tell me what's the best I can do at this point of time? and why is bubble sorting taking so long even with just 10 items?</p>