MobileModuleList.xaml.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using Xamarin.Forms;
  5. using Xamarin.Forms.Xaml;
  6. using XF.Material.Forms.UI;
  7. namespace InABox.Mobile
  8. {
  9. [XamlCompilation(XamlCompilationOptions.Compile)]
  10. public partial class MobileModuleList
  11. {
  12. public IList<IModuleMenuItem> Items { get; }
  13. public event EventHandler BeforeTap;
  14. public event EventHandler AfterTap;
  15. public MobileModuleList()
  16. {
  17. Items = new ObservableCollection<IModuleMenuItem>();
  18. InitializeComponent();
  19. Modules.ItemsSource = Items;
  20. }
  21. private bool debounce = false;
  22. private async void Module_Clicked(object sender, EventArgs e)
  23. {
  24. if (debounce)
  25. return;
  26. debounce = true;
  27. BeforeTap?.Invoke(this,EventArgs.Empty);
  28. try
  29. {
  30. if ((sender is MobileCard card) && (card.BindingContext is IModuleMenuItem module) && module.IsEnabled)
  31. {
  32. card.Scale = 0.5;
  33. await card.ScaleTo(1, 150);
  34. module.Tap();
  35. }
  36. }
  37. catch (Exception err)
  38. {
  39. MobileLogging.Log(err,"MobileToolGrid");
  40. }
  41. AfterTap?.Invoke(this, EventArgs.Empty);
  42. debounce = false;
  43. }
  44. }
  45. }