MobileToolItem.cs 4.0 KB

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