MobileToolItem.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Windows.Input;
  4. using Xamarin.Forms;
  5. namespace InABox.Mobile
  6. {
  7. public interface IMobileToolItem
  8. {
  9. string Text { get; set; }
  10. ImageSource Image { get; set; }
  11. string Alert { get; set; }
  12. bool IsEnabled { get; set; }
  13. bool IsVisible { get; set; }
  14. int ID { get; set; }
  15. event EventHandler Clicked;
  16. void DoTap();
  17. int Row { get; set; }
  18. int Column { get; set; }
  19. }
  20. public class MobileToolItem : BindableObject, IMobileToolItem
  21. {
  22. public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(MobileToolItem), "");
  23. public string Text
  24. {
  25. get { return (string)GetValue(TextProperty); }
  26. set { SetValue(TextProperty, value); }
  27. }
  28. public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(Image), typeof(ImageSource), typeof(MobileToolItem), null);
  29. public ImageSource Image
  30. {
  31. get { return (ImageSource)GetValue(ImageProperty); }
  32. set { SetValue(ImageProperty, value); }
  33. }
  34. public static readonly BindableProperty AlertProperty = BindableProperty.Create(
  35. nameof(Alert),
  36. typeof(string),
  37. typeof(MobileToolItem),
  38. null);
  39. public string Alert
  40. {
  41. get { return (string)GetValue(AlertProperty); }
  42. set {
  43. SetValue(AlertProperty, value);
  44. OnPropertyChanged(nameof(AlertVisible));
  45. }
  46. }
  47. public bool AlertVisible => !String.IsNullOrWhiteSpace(Alert);
  48. public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(
  49. nameof(BackgroundColor),
  50. typeof(Color),
  51. typeof(MobileToolItem),
  52. Color.White);
  53. public Color BackgroundColor
  54. {
  55. get => (Color)GetValue(BackgroundColorProperty);
  56. set => SetValue(BackgroundColorProperty, value);
  57. }
  58. public static readonly BindableProperty TextColorProperty = BindableProperty.Create(
  59. nameof(TextColor),
  60. typeof(Color),
  61. typeof(MobileToolItem),
  62. Color.Black);
  63. public Color TextColor
  64. {
  65. get => (Color)GetValue(TextColorProperty);
  66. set => SetValue(TextColorProperty, value);
  67. }
  68. public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(MobileToolItem), true);
  69. public bool IsEnabled
  70. {
  71. get { return (bool)GetValue(IsEnabledProperty); }
  72. set
  73. {
  74. SetValue(IsEnabledProperty, value);
  75. DoChanged();
  76. }
  77. }
  78. public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(MobileToolItem), true);
  79. public bool IsVisible
  80. {
  81. get { return (bool)GetValue(IsVisibleProperty); }
  82. set
  83. {
  84. SetValue(IsVisibleProperty, value);
  85. DoChanged();
  86. }
  87. }
  88. public static readonly BindableProperty RowProperty = BindableProperty.Create(nameof(Row), typeof(Int32), typeof(MobileToolItem));
  89. public Int32 Row
  90. {
  91. get { return (Int32)GetValue(RowProperty); }
  92. set { SetValue(RowProperty, value); }
  93. }
  94. public static readonly BindableProperty ColumnProperty = BindableProperty.Create(nameof(Column), typeof(Int32), typeof(MobileToolItem));
  95. public Int32 Column
  96. {
  97. get { return (Int32)GetValue(ColumnProperty); }
  98. set { SetValue(ColumnProperty, value); }
  99. }
  100. public int ID { get; set; }
  101. public event EventHandler Clicked;
  102. public void DoTap()
  103. {
  104. Clicked?.Invoke(this, EventArgs.Empty);
  105. }
  106. public event EventHandler Changed;
  107. public void DoChanged()
  108. {
  109. Changed?.Invoke(this, EventArgs.Empty);
  110. }
  111. }
  112. }