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.
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:
<ListBox ItemsSource="{Binding}"/>
into this:
<ListBox>
<ListBox.ItemsSource>
<my:ProxyCollection Source="{Binding}" SortBy="Name"/>
</ListBox.ItemsSource>
</ListBox>
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".
So any ideas on how I can automatically get the ListBox's DataContext set on the proxy collection? Or any other genius ideas?