ToolGrid.xaml.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using Xamarin.Forms;
  6. using Xamarin.Forms.Xaml;
  7. namespace comal.timesheets
  8. {
  9. public class ToolGridViewModel : BindableObject
  10. {
  11. public IList<IToolItem> Items { get; private set; }
  12. public IList<IToolItem> VisibleItems { get; private set; }
  13. public ToolGridViewModel()
  14. {
  15. Items = new ObservableCollection<IToolItem>();
  16. VisibleItems = new ObservableCollection<IToolItem>();
  17. ((ObservableCollection<IToolItem>)Items).CollectionChanged += (sender, args) =>
  18. {
  19. VisibleItems.Clear();
  20. foreach (var item in Items.Where(x=>x.IsVisible))
  21. VisibleItems.Add(item);
  22. };
  23. }
  24. }
  25. [XamlCompilation(XamlCompilationOptions.Compile)]
  26. public partial class ToolGrid
  27. {
  28. public IList<IToolItem> Items => _viewModel.Items;
  29. public ToolGrid()
  30. {
  31. InitializeComponent();
  32. BindableLayout.SetItemsSource(_flexgrid, _viewModel.VisibleItems);
  33. }
  34. private void ImageTapped(object sender, EventArgs e)
  35. {
  36. if ((sender is Image image) && (image.BindingContext is ToolItem item))
  37. item.DoTap();
  38. }
  39. }
  40. }