| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Globalization;
- using System.Linq;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace InABox.Mobile
- {
-
- 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);
- };
- }
-
- public Color BackgroundColor { get; set; }
-
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class MobileToolGrid
- {
- public IList<IToolItem> Items => _viewModel.Items;
-
- public MobileToolGrid()
- {
- InitializeComponent();
- BindableLayout.SetItemsSource(_flexgrid, _viewModel.VisibleItems);
- }
-
- private void ImageTapped(object sender, EventArgs e)
- {
- if ((sender is Image image) && (image.BindingContext is MobileToolItem item) && item.IsEnabled)
- item.DoTap();
- }
- }
- }
|