title: Binding ItemsSource to a "proxy" collection. How to get DataContext?
body: <p>We've got a Silverlight application with several listboxes and comboboxes that display data sorted incorrectly, which I need to fix. Most of their ItemSource properties are set through XAML. Their DataContext may not be set directly on the control, and instead were set on a parent. So I can't easily slap an "OrderBy" on the ItemSource or DataContext assignment in the code behind, since that assignment may not explicitly exist.</p>
  
  <p>So I had the idea to create a "proxy" collection. The proxy collection would get the original ItemSource and expose a sorted version. I'd then be able to convert this:</p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding}"/&gt;
  </code></pre>
  
  <p>into this:</p>
  
  <pre><code>&lt;ListBox&gt;
      &lt;ListBox.ItemsSource&gt;
          &lt;my:ProxyCollection Source="{Binding}" SortBy="Name"/&gt;
      &lt;/ListBox.ItemsSource&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>Not too shabby! But, since the ProxyCollection isn't a child of the ListBox, the ListBox's DataContext isn't propagated to it, and the binding doesn't magically work. If I manually set the ProxyCollection collection's DataContext it works great. But if I have to set the DataContext manually anyways I may as well just remove the proxy collection and manually set the Listbox's DataContext, adding an "OrderBy".</p>
  
  <p>So any ideas on how I can automatically get the ListBox's DataContext set on the proxy collection? Or any other genius ideas?</p>