SelectionPage.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using Xamarin.Forms;
  3. using Xamarin.Forms.Xaml;
  4. namespace comal.timesheets
  5. {
  6. [XamlCompilation(XamlCompilationOptions.Compile)]
  7. public partial class SelectionPage
  8. {
  9. private SelectionPageMode _mode;
  10. private Action<MobileGridColumns> _configure;
  11. private Func<bool,object> _refresh;
  12. private Action<object[]> _selected;
  13. public SelectionPage(
  14. String title,
  15. SelectionPageMode mode,
  16. Action<MobileGridColumns> configure,
  17. Func<bool,object> refresh,
  18. Action<object[]> selected)
  19. {
  20. _mode = mode;
  21. _configure = configure;
  22. _refresh = refresh;
  23. _selected = selected;
  24. InitializeComponent();
  25. Title = title;
  26. _selection.Mode = mode;
  27. if (_mode != SelectionPageMode.Immediate)
  28. {
  29. ToolbarItems.Clear();
  30. ToolbarItems.Add(new ToolbarItem("Select", null, DoSelectItems));
  31. }
  32. }
  33. protected override void OnAppearing()
  34. {
  35. _selection.Load();
  36. base.OnAppearing();
  37. }
  38. private void DoSelectItems()
  39. {
  40. _selected?.Invoke(_selection.SelectedItems);
  41. Navigation.PopAsync();
  42. }
  43. private void _selection_OnConfigureColumns(object sender, SelectionViewConfigureArgs args)
  44. {
  45. _configure?.Invoke(args.Columns);
  46. }
  47. private object _selection_OnRefresh(object sender, SelectionViewRefreshArgs args)
  48. {
  49. return _refresh?.Invoke(false);
  50. }
  51. private void _selection_OnSelectionChanged(object sender, SelectionViewSelectionChangedArgs args)
  52. {
  53. if (_mode == SelectionPageMode.Immediate)
  54. DoSelectItems();
  55. }
  56. }
  57. }