【发布时间】:2009-08-14 23:44:43
【问题描述】:
我需要对ListBox 中的字符串进行排序,但它由另一个组件通过DataContext 绑定到视图模型。所以我不能直接在 XAML 中实例化视图模型,就像在 this example 中一样,它使用了 ObjectDataProvider。
在我的 XAML 中:
<ListBox ItemsSource="{Binding CollectionOfStrings}" />
在我的视图模型中:
public ObservableCollection<string> CollectionOfStrings
{
get { return collectionOfStrings; }
}
在另一个组件中:
view.DataContext = new ViewModel();
后面没有代码!那么使用纯粹的 XAML,我将如何对 ListBox 中的项目进行排序?同样,XAML 不拥有视图模型的实例化。
【问题讨论】:
标签: wpf xaml sorting mvvm listbox