title: Bind to a sorted ObservableCollection<T> in a ListBox
body: <p>I have a list of data objects in my Windows Phone 7 application called <code>MyObjectList</code>, which inherits <code>ObservableCollection&lt;MyObject&gt;</code>. I keep the list in memory in a public property of <code>App</code> called <code>MyObjects</code>. My goal is to bind the data to a <code>ListBox</code> and have it sorted by <code>MyObject.Name</code>.</p>
  
  <p>Currently, I have a <code>ListBox</code> in XAML with the name <code>MyObjectsList</code> and the following code in the constructor to link it up:</p>
  
  <pre><code>public MyObjectListView()
  {
      InitializeComponent();
      this.MyObjectsList.ItemsSource = ((App)App.Current).MyObjects;
  }
  </code></pre>
  
  <p>This works great. I add items to <code>MyObjects</code> and they show up in the <code>ListBox</code>. However, the data isn't sorted by name when it appears in the list. I tried the following change to get the data to be sorted:</p>
  
  <pre><code>this.MyObjectsList.ItemsSource = ((App)App.Current).MyObjects
                                           .OrderBy(x =&gt; x.Name)
  </code></pre>
  
  <p>But when I do that, I don't see <em>any</em> objects reflected in the <code>ListBox</code> sorted or otherwise.</p>
  
  <p>What can I do so that when I add an item to my <code>ObservableCollection</code>, it shows up sorted by <code>.Name</code> in the <code>ListBox</code>?</p>