public MainPage()
        {
            InitializeComponent();
            MyCollectionView.BindingContext = this;
            MyCollectionView.SetBinding(ItemsView.ItemsSourceProperty, nameof(ControlList));

            for (var x = 0; x < 20; x++)
            {
                ControlList.Add(new Label {
                    Text = $"Added at {ControlList.Count}"
                });
            }
        }
예제 #2
0
        public MainPage()
        {
            InitializeComponent();

            //Example of creating a binding from code
            MyCollectionView.SetBinding(ItemsView.ItemsSourceProperty, new Binding(nameof(Items), source: this));

            _groceriesRepository = new GroceriesRepository();
            var items = _groceriesRepository.GetAll().Result;

            foreach (var item in items)
            {
                Items.Add(item);
            }

            MessageBus.Subscribe <ItemAdded>(async e =>
            {
                await _groceriesRepository.Save(e.GroceryListItem);
                Items.Add(e.GroceryListItem);
            });
        }
예제 #3
0
        public MainPage()
        {
            InitializeComponent();

            MyCollectionView.SetBinding(
                CollectionView.ItemsSourceProperty,
                new Binding(nameof(Items), source: this));

            Device.StartTimer(TimeSpan.FromSeconds(1.5), () =>
            {
                var wordCount = _rng.Next(1, 30);
                var words     = new List <string>();

                for (var i = 0; i < wordCount; i++)
                {
                    words.Add(_randomText[_rng.Next(0, _randomText.Count - 1)]);
                }

                Items.Add(string.Join(" ", words));

                return(true);
            });
        }