ContactGrid.cs 1.2 KB

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