ToolItem.cs 3.9 KB

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