ToolEntry.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using Xamarin.Forms;
  6. namespace comal.timesheets
  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 int ID { get; set; }
  23. public event EventHandler OnTapped;
  24. public ToolEntry(string notification = "")
  25. {
  26. InitializeComponent();
  27. if (!string.IsNullOrEmpty(notification))
  28. {
  29. notificationFrame.IsVisible = true;
  30. toolEntryLbl.Text = notification;
  31. Timer t = new Timer(NotificationJump, null, 0, 5000);
  32. }
  33. }
  34. public ToolEntry()
  35. {
  36. InitializeComponent();
  37. }
  38. async void NotificationJump(object o)
  39. {
  40. Device.BeginInvokeOnMainThread(async () =>
  41. {
  42. await notificationFrame.TranslateTo(0, -10, 250);
  43. await notificationFrame.TranslateTo(0, 0, 250);
  44. });
  45. }
  46. public ToolEntry(bool invisible)
  47. {
  48. InitializeComponent();
  49. if (invisible)
  50. {
  51. toolFrame.IsVisible = false;
  52. }
  53. }
  54. async void ImageTapped(System.Object sender, System.EventArgs e)
  55. {
  56. await toolFrame.TranslateTo(0, -15, 150);
  57. await toolFrame.TranslateTo(0, 0, 150);
  58. OnTapped?.Invoke(this, new EventArgs());
  59. }
  60. }
  61. }