我在WPF中没有MVVM的应用程序,我决定将此重构为MVVM。我遇到了ComboBox SelectionChanged事件的问题。基本上,让简单让我们假设我有一个组合框和2个ListView的。每个ComboBoxItem都是一个集合。第一个ListView的ItemsSource绑定到来自ComboBox.SelectedValue的集合,但仅限于其一个属性(十进制)大于零的部分。第二个ListView的ItemsSource绑定到相同的集合,但是到第二个部分(一些prop大于零)。下面一些代码要了解MVVM中的ComboBox SelectionChanged
private void myCombo_selectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox myCmb = sender as ComboBox;
List<myType> myList = myCmb.SelectedValue as List<myType>;
itemsForListView1 = myList.Where((x) => x.myProp > 0);
itemsForListView2 = myList.Where((x) => x.myProp < 0);
// Above 2 collections are of Type List<myType> and their scope will be whole ViewModel,
//so i assume i just need to change them and RaisePropChanged but how to change them without breaking mvvm ?
MyListView1.ItemsSource = itemsForListView1;
MyListView2.ItemsSource = itemsForListView2;
}
我该如何实现MVVM中类似的东西?
将此事件方法设置为属性,该属性可以自我提升并使用其他属性与列表视图进行绑定。 – JSJ
我对MVVM真的很陌生,所以我会用一些进一步的描述来欣赏一些exmaple – MajkeloDev