1.页面
<ItemsControl ItemsSource="{Binding CourseList}" Name="icCourses">
<RadioButton Content="{Binding CategoryName}" IsChecked="{Binding IsSelected}" Template="{StaticResource CategoryItemButtonTemplate}" Margin="5,0"
GroupName="teacher"
Click="RadioButton_Click"/>
2.过滤相关事件
private void RadioButton_Click(object sender, RoutedEventArgs e)
{
RadioButton button = sender as RadioButton;
string teacher = button.Content.ToString();
ICollectionView view = CollectionViewSource.GetDefaultView(this.icCourses.ItemsSource);
if (teacher == "全部")
{
view.Filter = null;
//排序
//view.SortDescriptions.Add(new SortDescription("CourseName", ListSortDirection.Descending));
}
else
{
view.Filter = new Predicate<object>((o) =>
{
return (o as CourseModel).Teachers.Exists(t => t == teacher);
});
}
}