MobileModuleList.xaml.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 as MobileCard)?.BindingContext is IModuleMenuItem module) && module.IsEnabled)
  31. module.Tap();
  32. }
  33. catch (Exception err)
  34. {
  35. MobileLogging.Log(err,"MobileToolGrid");
  36. }
  37. AfterTap?.Invoke(this, EventArgs.Empty);
  38. debounce = false;
  39. }
  40. }
  41. }