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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…