EquipmentList.xaml.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using comal.timesheets.Tasks;
  5. using Xamarin.Forms;
  6. using Xamarin.Forms.Xaml;
  7. namespace comal.timesheets
  8. {
  9. [XamlCompilation(XamlCompilationOptions.Compile)]
  10. public partial class EquipmentList
  11. {
  12. public EquipmentList()
  13. {
  14. InitializeComponent();
  15. Equipment.Columns
  16. .BeginUpdate()
  17. .Clear()
  18. .Add(new MobileGridTextColumn<EquipmentShell>() { Column = x => x.Code, Width = 100 })
  19. .Add(new MobileGridTextColumn<EquipmentShell>() { Column = x => x.Description, Width = GridLength.Star })
  20. .EndUpdate();
  21. RefreshData(false);
  22. }
  23. private void RefreshData(bool force)
  24. {
  25. App.Data.Equipment.Refresh(force,
  26. () => Device.BeginInvokeOnMainThread(() =>
  27. {
  28. Equipment.ItemsSource = App.Data.Equipment.Items;
  29. })
  30. );
  31. }
  32. private void Equipment_OnRefreshRequested(object sender, MobileGridRefreshRequestArgs args)
  33. {
  34. RefreshData(true);
  35. }
  36. private void Equipment_OnSelectionChanged(object sender, MobileGridSelectionArgs args)
  37. {
  38. var shell = args.Selection.FirstOrDefault() as EquipmentShell;
  39. if (shell != null)
  40. {
  41. EquipmentDetailsPage page = new EquipmentDetailsPage(shell.ID);
  42. Navigation.PushAsync(page);
  43. }
  44. }
  45. }
  46. }