async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (list.SelectedItem == null)
            {
                return;
            }

            var vm = list.SelectedItem as LeagueViewModel;

            list.SelectedItem = null;

            //Empty message
            if (vm.LeagueId == null)
            {
                return;
            }

            var page = new LeagueDetailsPage(vm.League);

            page.OnJoinedLeague = (l) =>
            {
                ViewModel.LocalRefresh();
                if (OnJoinedLeague != null)
                {
                    OnJoinedLeague(l);
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopAsync();
                });
            };

            await Navigation.PushAsync(page);
        }
Пример #2
0
        async void OnListItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            //This event gets triggered when you set SelectedItem to null or the item is deselected by the user so we need to check for null first
            if (list.SelectedItem == null)
            {
                return;
            }

            var vm = list.SelectedItem as LeagueViewModel;

            list.SelectedItem = null;           //Deselect the item

            if (vm.LeagueId == null)            //Ensure the league is a valid league - some items in this list are used to display an empty message and do not have a LeagueId
            {
                return;
            }

            //Referencing 'this' in the body of delegate will prevent the page from being collected once it's popped
            var weakSelf = new WeakReference(this);
            var page     = new LeagueDetailsPage(vm.League);

            page.OnAbandondedLeague = (async(l) =>
            {
                var self = (AthleteLeaguesPage)weakSelf.Target;
                if (self == null)
                {
                    return;
                }

                self.ViewModel.LocalRefresh();
                self.ViewModel.SetPropertyChanged("Athlete");
                await self.Navigation.PopAsync();
            });

            await Navigation.PushAsync(page);
        }