12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace comal.timesheets
- {
- public class ToolGridViewModel : BindableObject
- {
- public IList<IToolItem> Items { get; private set; }
- public IList<IToolItem> VisibleItems { get; private set; }
-
- public ToolGridViewModel()
- {
- Items = new ObservableCollection<IToolItem>();
- VisibleItems = new ObservableCollection<IToolItem>();
- ((ObservableCollection<IToolItem>)Items).CollectionChanged += (sender, args) =>
- {
- VisibleItems.Clear();
- foreach (var item in Items.Where(x=>x.IsVisible))
- VisibleItems.Add(item);
- };
- }
-
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ToolGrid
- {
- public IList<IToolItem> Items => _viewModel.Items;
-
- public ToolGrid()
- {
- InitializeComponent();
- BindableLayout.SetItemsSource(_flexgrid, _viewModel.VisibleItems);
- }
-
- private void ImageTapped(object sender, EventArgs e)
- {
- if ((sender is Image image) && (image.BindingContext is ToolItem item))
- item.DoTap();
- }
- }
- }
|