ToolEntry.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using Xamarin.Forms;
  6. namespace PRS.Mobile
  7. {
  8. public partial class ToolEntry : Grid
  9. {
  10. public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(ToolEntry), "");
  11. public string Text
  12. {
  13. get { return (string)GetValue(TextProperty); }
  14. set { SetValue(TextProperty, value); }
  15. }
  16. public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(Image), typeof(ImageSource), typeof(ToolEntry), null);
  17. public ImageSource Image
  18. {
  19. get { return (ImageSource)GetValue(ImageProperty); }
  20. set { SetValue(ImageProperty, value); }
  21. }
  22. public static readonly BindableProperty IndicatorProperty = BindableProperty.Create(nameof(Indicator), typeof(string), typeof(ToolEntry), null);
  23. public string Indicator
  24. {
  25. get { return (string)GetValue(IndicatorProperty); }
  26. set
  27. {
  28. SetValue(IndicatorProperty, value);
  29. UpdateIndicator();
  30. }
  31. }
  32. public int ID { get; set; }
  33. public event EventHandler Tapped;
  34. public ToolEntry()
  35. {
  36. InitializeComponent();
  37. }
  38. private void UpdateIndicator()
  39. {
  40. if (!String.IsNullOrWhiteSpace(Indicator))
  41. {
  42. indicatorLbl.Text = Indicator;
  43. indicatorFrame.IsVisible = true;
  44. Task.Run(() =>
  45. {
  46. Thread.Sleep(1000);
  47. Device.BeginInvokeOnMainThread(() =>
  48. {
  49. indicatorFrame.TranslateTo(0, -10, 250);
  50. indicatorFrame.TranslateTo(0, 0, 250);
  51. });
  52. });
  53. }
  54. else
  55. indicatorFrame.IsVisible = false;
  56. }
  57. async void ImageTapped(System.Object sender, System.EventArgs e)
  58. {
  59. await toolFrame.TranslateTo(0, -15, 150);
  60. await toolFrame.TranslateTo(0, 0, 150);
  61. Tapped?.Invoke(this, new EventArgs());
  62. }
  63. }
  64. }