ContactGrid.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Windows.Controls;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. namespace PRSDesktop
  7. {
  8. public class ContactGrid : DynamicDataGrid<Contact>
  9. {
  10. private bool bShowAll;
  11. public ContactGrid()
  12. {
  13. Options.AddRange(
  14. DynamicGridOption.RecordCount,
  15. DynamicGridOption.FilterRows,
  16. DynamicGridOption.SelectColumns
  17. );
  18. AddButton("Show All", null, ToggleFavourites);
  19. }
  20. private bool ToggleFavourites(Button sender, CoreRow[] rows)
  21. {
  22. bShowAll = !bShowAll;
  23. UpdateButton(sender, null, bShowAll ? "Favourites" : "Show All");
  24. return true;
  25. }
  26. protected override void Reload(Filters<Contact> criteria, Columns<Contact> columns, ref SortOrder<Contact> sort,
  27. Action<CoreTable, Exception> action)
  28. {
  29. if (!bShowAll)
  30. criteria.Add(new Filter<Contact>(x => x.Favourite).IsEqualTo(true));
  31. base.Reload(criteria, columns, ref sort, action);
  32. }
  33. }
  34. }