LookupModel.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using InABox.Core;
  4. using System.Diagnostics.CodeAnalysis;
  5. using Xamarin.Forms;
  6. namespace InABox.Mobile
  7. {
  8. public abstract class LookupModel<TParent, TItem, TEntity> : ListModel<TParent, TItem, TEntity>, ILookupModel
  9. where TParent : LookupModel<TParent, TItem, TEntity>
  10. where TEntity : Entity, IRemotable, IPersistent, new()
  11. where TItem : Shell<TParent, TEntity>, ILookupShell, new()
  12. {
  13. protected LookupModel(IModelHost host, Func<Filter<TEntity>> filter, bool transient = false) : base(
  14. host, filter, transient)
  15. {
  16. }
  17. protected LookupModel(IModelHost host, Func<Filter<TEntity>> filter, [NotNull] string filename) : base(
  18. host, filter, filename)
  19. {
  20. }
  21. protected override void Initialize()
  22. {
  23. base.Initialize();
  24. _selected.Clear();
  25. }
  26. private List<Guid> _selected = new List<Guid>();
  27. public void Select(ILookupShell shell)
  28. {
  29. foreach (var _item in Items)
  30. _item.Selected = _item == shell;
  31. }
  32. public Color Selected { get; set; }
  33. public Color Background { get; set; }
  34. }
  35. }