//Called if user taps a row (as opposed to programatically changing the selection)
        private void PlanetListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            SolPlanet item        = (SolPlanet)e.Item;
            int       selectedRow = e.ItemIndex;

            vm.UserTappedList(row: selectedRow, planet: item);
        }
        public PlanetDetailViewModel(SolPlanet p, INavigation nav) : base(nav)
        {
            //Keep a reference to the original
            _original = p;

            //Make an indepednent copy
            Model = new SolPlanet(p);

            //Commands
            SaveCommand = new Command(execute: () =>
            {
                //Note if the group needs changing
                bool hasMovedGroup = (_original.Explored != Model.Explored);

                //Update the original planet data (mutable reference type)
                _original.Copy(Model);

                //Message back if the group has changed
                if (hasMovedGroup)
                {
                    MessagingCenter.Send(this, "PlanetUpdated", _original);
                }

                //Navigate back
                _ = Navigation.PopAsync();
            });
        }
Example #3
0
        //Called if the item selection changes (by any means)
        private void PlanetListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            //If nothing is selected, there is nothing to do
            if (e.SelectedItem == null)
            {
                return;
            }

            //Extract data
            SolPlanet item        = (SolPlanet)e.SelectedItem;
            int       selectedRow = e.SelectedItemIndex;

            //Update ViewModel
            vm.ItemSelectionChanged(row: selectedRow, planet: item);
        }
Example #4
0
        public PlanetDetailViewModel(SolPlanet p, INavigation nav) : base(nav)
        {
            //Keep a reference to the original
            _original = p;

            //Make an indepednent copy
            Model = new SolPlanet(p);

            //Commands
            SaveCommand = new Command(execute: () =>
            {
                Save();
                _ = Navigation.PopAsync();
            });
        }