I need to sort the strings in a ListBox
, but it is bound to the view model by another component via the DataContext
. So I can't directly instantiate the view model in XAML, as in this example, which uses the ObjectDataProvider
.
In my XAML:
<ListBox ItemsSource="{Binding CollectionOfStrings}" />
In my view model:
public ObservableCollection<string> CollectionOfStrings
{
get { return collectionOfStrings; }
}
In another component:
view.DataContext = new ViewModel();
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.