(精华)2020年02月09日 WPF课程管理系统项目实战(内容中心-FilTer过滤排序)

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);
        });
    }
}
上一篇:radioButton可选择后取消


下一篇:跟我学Android之五 常规组件