title: How can I sort a ListBox using only XAML and no code-behind?
body: <p>I need to sort the strings in a <code>ListBox</code>, but it is bound to the view model by another component via the <code>DataContext</code>. So I can't directly instantiate the view model in XAML, as in <a href="http://www.galasoft.ch/mydotnet/articles/article-2007081301.aspx" rel="noreferrer">this example</a>, which uses the <code>ObjectDataProvider</code>.</p>
  
  <p>In my XAML:</p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding CollectionOfStrings}" /&gt;
  </code></pre>
  
  <p>In my view model:</p>
  
  <pre><code>public ObservableCollection&lt;string&gt; CollectionOfStrings
  {
      get { return collectionOfStrings; }
  }
  </code></pre>
  
  <p>In another component:</p>
  
  <pre><code>view.DataContext = new ViewModel();
  </code></pre>
  
  <p>There is no code behind! So using purely XAML, how would I sort the items in the ListBox? Again, the XAML doesn't own the instantiation of the view model.</p>