码迷,mamicode.com
首页 > Windows程序 > 详细

wpf listbox分页

时间:2017-02-28 13:14:25      阅读:484      评论:0      收藏:0      [点我收藏+]

标签:log   数据   bitmap   容量   for   ati   use   event   mod   

        List<ListBoxItem> llb;//符合条件像的listbox数据集合
      public static List<ModelDataBase> datalist = new List<ModelDataBase>();//总的数据源
      int pageIndex = 1;//当前页
      int pageSize = 16;//一页最大容量
      int totalPage = 0;//总页数

      public void TakePage()
        {
            tbindex.Text = pageIndex.ToString();
            listBox.ItemsSource = llb.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
        }

//首页
      private void btnFirst_Click(object sender, RoutedEventArgs e)
        {
            pageIndex = 1;
            TakePage();
        }

        //尾页
      private void btnLast_Click(object sender, RoutedEventArgs e)
        {
            pageIndex = totalPage;
            TakePage();
        }

        //上一页
      private void btnPrev_Click(object sender, RoutedEventArgs e)
        {
            if (pageIndex > 1)
            {
                pageIndex -= 1; TakePage();
            }
        }

        //下一页
      private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (pageIndex < totalPage)
            {
                pageIndex += 1;
                TakePage();
            }
        }

public List<ListBoxItem> BoundData(int _pageIndex, int _pageSize, string strString,string sign)
        {
            llb = new List<ListBoxItem>();
            List<ModelDataBase> listmodel = null;
            if (sign.Equals("1"))
            {
                listmodel = datalist.FindAll(item => (int)item._ParentID == Convert.ToInt64(strString));
            }
            else if (sign.Equals("0"))
            {
                listmodel = datalist.Where(s => s._ModelName.Contains(strString)).ToList();
            }
            else
            {
                listmodel = datalist.Where(s => s._ModelName == strString).ToList();
            }
            foreach (ModelDataBase item in listmodel)
            {
                ListBoxItem lbi = new ListBoxItem();
                lbi.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
                StackPanel sp = new StackPanel();
                Image img = new Image();
                string url = item._ModelURL;
                img.Source = new BitmapImage(new Uri(@url, UriKind.Relative));
                System.Windows.Controls.Label lable = new System.Windows.Controls.Label();
                lable.Content = item._ModelName;
                sp.Children.Add(img);
                sp.Children.Add(lable);
                sp.Tag = item._MidelRemark;
                lbi.Content = sp;
                lbi.MouseDoubleClick += Lbi_MouseDoubleClick;
                llb.Add(lbi);
            }
            //初始化分页元素
            pageIndex = 1;
            tbindex.Text = pageIndex.ToString();
            int count = listmodel.Count;//总数据条数
            if (count % pageSize == 0)
            {
                totalPage = count / pageSize;
            }
            else
            {
                totalPage = count / pageSize + 1;
            }
            tbmax.Text = totalPage.ToString();
            DisableClick(true);
            return llb.Skip(0).Take(pageSize).ToList();
        }

 

wpf listbox分页

标签:log   数据   bitmap   容量   for   ati   use   event   mod   

原文地址:http://www.cnblogs.com/chendongbky/p/6478262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!