WPF Listview 排序加分页

2021-02-15 13:22

阅读:447

标签:center   width   for   初始   panel   sts   resource   temp   less   

RadioButton radio = sender as RadioButton;
            courseHoursList.Items.SortDescriptions.Clear();
            if (radio.Name == "sort_asc")
            {
                courseHoursList.Items.SortDescriptions.Add(new SortDescription("create_time", ListSortDirection.Ascending));
            }
            else
            {
                courseHoursList.Items.SortDescriptions.Add(new SortDescription("create_time", ListSortDirection.Descending));
            }

  

分页

#region  分页

        private void but_Pages_Click(object sender, RoutedEventArgs e)
        {
            Fun_Pager(((sender as Button).DataContext as Page).PageSize);
        }


        private int _number;
        public int Number
        {
            get { return _number; }
            set
            {
                _number = value;
                OnPropertyChanged("Number");
            }
        }

        private int _currentSize;
        public int CurrentSize
        {
            get { return _currentSize; }
            set
            {
                _currentSize = value;
                OnPropertyChanged("CurrentSize");
            }
        }

        private int _total;
        public int Total
        {
            get { return _total; }
            set
            {
                _total = value;
                OnPropertyChanged("Total");
            }
        }

        private List _pages;
        public List Pages
        {
            get { return _pages; }
            set
            {
                _pages = value;
                OnPropertyChanged("Pages");
            }
        }

        private List _listRegDept;
        public List ListRegDept
        {
            get { return _listRegDept; }
            set
            {
                _listRegDept = value;
                OnPropertyChanged("ListRegDept");
            }
        }

        private List _listBind;
        public List ListBind
        {
            get { return _listBind; }
            set
            {
                _listBind = value;
                OnPropertyChanged("ListBind");
            }
        }

        //初始化,传list
        public void ViewPages(List lessonInfos)
        {
            LessonInfo dataOP = new LessonInfo();
            this.Number = 1;//设置每页显示数目
            this.ListRegDept = new List();//初始化数据
            ListRegDept = lessonInfos;

            if ((ListRegDept.Count() % this.Number) > 0)
            {
                this.Total = ListRegDept.Count() / this.Number + 1;//获取总页数
            }
            else
            {
                this.Total = ListRegDept.Count() / this.Number;//获取总页数
            }

            this.Pages = new List();//初始化所有页数数组
            for (int i = 1; i 
        /// 分页方法
        /// 
        /// 当前页数
        public void Fun_Pager(int CurrentSize)
        {
            this.CurrentSize = CurrentSize;
            this.ListBind = this.ListRegDept.Take(this.Number * this.CurrentSize)
                .Skip(this.Number * (this.CurrentSize - 1)).ToList();

            dataList.ItemsSource = this.ListBind;
        }

        private void btnHome_Click(object sender, RoutedEventArgs e)
        {
            Fun_Pager(1);
        }

        private void btnEnd_Click(object sender, RoutedEventArgs e)
        {
            Fun_Pager(this.Pages.Count);
        }

        private void btnLast_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentSize > 1)
            {
                Fun_Pager(CurrentSize - 1);
            }
        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentSize 

  添加在listview 下面

StackPanel Grid.Row="4"  Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed">
            StackPanel Orientation="Horizontal">
                Button Content="首页" Style="{DynamicResource PageNumButton}" Click="btnHome_Click" Margin="0,0,10,0" Foreground="#393838" Background="White" FontSize="12" Width="40" Height="22" Cursor="Hand"/>
                
                Button Content="上一页" Style="{DynamicResource PageNumButton}" Click="btnLast_Click" Margin="0,0,10,0" Foreground="#393838" Background="White" FontSize="12" Width="40" Height="22" Cursor="Hand"/>
                Button Content="下一页" Style="{DynamicResource PageNumButton}" Click="btnNext_Click" Margin="0,0,10,0" Foreground="#393838" Background="White" FontSize="12" Width="40" Height="22" Cursor="Hand"/>
                Button Content="尾页" Style="{DynamicResource PageNumButton}" Click="btnEnd_Click"  Foreground="#393838" Background="White" FontSize="12" Width="40" Height="22" Cursor="Hand"/>
            StackPanel>
            TextBlock VerticalAlignment="Center" Margin="20,0,0,0" FontSize="10">
                TextBlock Text="【共"/>
                TextBlock Text="{Binding Total}" Foreground="#329FEE"/>
                TextBlock Text="页】"/>
                TextBlock Text="【当前第"/>
                TextBlock Text="{Binding CurrentSize}" Foreground="#329FEE" />
                TextBlock Text="页】"/>
            TextBlock>
        StackPanel>

 

WPF Listview 排序加分页

标签:center   width   for   初始   panel   sts   resource   temp   less   

原文地址:https://www.cnblogs.com/candyzhmm/p/12713831.html


评论


亲,登录后才可以留言!