ExpanderViewData.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Xamarin.Forms;
  5. namespace PRS.Mobile
  6. {
  7. public class ExpanderViewItem
  8. {
  9. public String Description { get; set; }
  10. public bool Selected { get; set; }
  11. }
  12. public class ExpanderViewGroup
  13. {
  14. public String Description { get; set; }
  15. public ImageSource Image { get; set; }
  16. private List<ExpanderViewItem> _items = new List<ExpanderViewItem>();
  17. public ExpanderViewItem[] Items => _items.ToArray();
  18. public ExpanderViewGroup AddItem(ExpanderViewItem item)
  19. {
  20. _items.Add(item);
  21. return this;
  22. }
  23. public void DeleteItem(ExpanderViewItem item)
  24. {
  25. if (_items.Contains(item))
  26. _items.Remove(item);
  27. }
  28. public void Clear() => _items.Clear();
  29. }
  30. public class ExpanderViewData
  31. {
  32. private List<ExpanderViewGroup> _groups = new List<ExpanderViewGroup>();
  33. public ExpanderViewGroup[] Groups => _groups.ToArray();
  34. public ExpanderViewGroup AddGroup(ExpanderViewGroup group)
  35. {
  36. _groups.Add(group);
  37. return group;
  38. }
  39. public void DeleteGroup(ExpanderViewGroup group)
  40. {
  41. if (_groups.Contains(group))
  42. _groups.Remove(group);
  43. }
  44. public void Clear() => _groups.Clear();
  45. public ExpanderViewItem[] SelectedItems
  46. {
  47. get
  48. {
  49. List<ExpanderViewItem> results = new List<ExpanderViewItem>();
  50. foreach (var group in Groups)
  51. results.AddRange(group.Items.Where(x => x.Selected));
  52. return results.ToArray();
  53. }
  54. }
  55. }
  56. }