我有List<参数> = App.ViewModel.Items其中Parameter有一个字符串Category。在List中,有30个参数,有4个不同的类别(头部,颈部,耳朵和喉咙)。该列表填充主页面上的MainLongListSelector。
我使用:
填充_categorySelector(ListPicker) _categorySelector.ItemsSource = App.ViewModel.Items.Select(m => m.Category).Distinct().ToList();
在SelectionChanged事件处理程序中,我想使用ListPicker的选定值过滤到MainLongListSelector。
到目前为止,我有这个,但这不起作用:
private void _categorySelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var query = (from jj in App.ViewModel.Items
where (_categorySelector.SelectedItem as Parameter).Category == jj.Category
select jj).ToList(); //doesn't work
var qq = App.ViewModel.Items.Select(mm => mm.Category).Distinct(); //doesn't connect selected item content to query
MainLongListSelector.ItemsSource = query;
}
答案 0 :(得分:0)
如何先收集正确的类型,然后使用Where子句:
var cat = (_categorySelector.SelectedItem as Parameter).Category;
var query = App.ViewModel.Items.OfType<Parameter>().Where(jj => jj.Category == cat).ToList();