MobileViewModel.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using InABox.Core;
  2. using Xamarin.Forms;
  3. namespace InABox.Mobile
  4. {
  5. public abstract class MobileViewModel : BindableObject, IMobileViewModel
  6. {
  7. public Color SelectedColor => XF.Material.Forms.Material.Color.Surface;
  8. public Color SelectedTextColor => XF.Material.Forms.Material.Color.OnSurface;
  9. public Color UnselectedColor => XF.Material.Forms.Material.Color.Primary;
  10. public Color UnselectedTextColor => XF.Material.Forms.Material.Color.OnPrimary;
  11. public event MobileViewModelLoadedEvent Loaded;
  12. protected void OnLoaded()
  13. => Loaded?.Invoke(this, new MobileViewModelLoadedEventArgs());
  14. }
  15. public abstract class MobileViewModel<TEntity,TShell> : MobileViewModel
  16. where TEntity : Entity, IRemotable, IPersistent
  17. where TShell : IShell<TEntity>
  18. {
  19. public static readonly BindableProperty ItemProperty = BindableProperty.Create(
  20. nameof(Item),
  21. typeof(TShell),
  22. typeof(MobileViewModel<TEntity,TShell>)
  23. );
  24. public TShell Item
  25. {
  26. get => (TShell)GetValue(ItemProperty);
  27. set
  28. {
  29. SetValue(ItemProperty,value);
  30. DoLoad();
  31. OnLoaded();
  32. }
  33. }
  34. protected abstract void DoLoad();
  35. }
  36. }