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

(精华)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);
        });
    }
}

标签:02,Filter,sender,09,FilTer,RadioButton,new,teacher,view
来源: https://blog.csdn.net/aa2528877987/article/details/113776079