PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/CSWPFPaging/ReadMe.txt

#
Plain Text | 55 lines | 33 code | 22 blank | 0 comment | 0 complexity | 005d6fd9ffa15fe503651e895c1a526f MD5 | raw file
  1. ================================================================================
  2. WPF APPLICATION : CSWPFPaging Project Overview
  3. WPF Paging Sample
  4. ===============================================================================
  5. /////////////////////////////////////////////////////////////////////////////
  6. Use:
  7. The sample demonstrates how to page data in WPF.
  8. /////////////////////////////////////////////////////////////////////////////
  9. Code Logic:
  10. 1. Create a Customer class with properties of ID, Name, Age, Country, etc.
  11. 2. Define a ListView with columns binding to each properties of the Customer object;
  12. 3. Drag 4 buttons on to the MainWindow, which are for displaying first, previous,
  13. next, last page.
  14. 4. Construct an ObservableCollection collection of Customer objects.
  15. 5. Create a CollectionViewSource object and set source to the customer list.
  16. 6. Handle the CollectionViewSource.Filter event to show data only in the current page.
  17. void view_Filter(object sender, FilterEventArgs e)
  18. {
  19. int index = customers.IndexOf((Customer)e.Item);
  20. if (index >= itemPerPage * currentPageIndex && index <
  21. itemPerPage * (currentPageIndex + 1))
  22. {
  23. e.Accepted = true;
  24. }
  25. else
  26. {
  27. e.Accepted = false;
  28. }
  29. }
  30. 7. Binding the CollectionViewSource object to the ListView.
  31. /////////////////////////////////////////////////////////////////////////////
  32. References:
  33. /////////////////////////////////////////////////////////////////////////////