MobileToolItem.cs 4.8 KB

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