async Task NavigateToRandomPageAsync() { string destinationRoute = routes.ElementAt(rand.Next(0, routes.Count)).Key; string animalName = string.Empty; //switch (destinationRoute) //{ // case "monkeydetails": // animalName = MonkeyData.Monkeys.ElementAt(rand.Next(0, MonkeyData.Monkeys.Count)).Name; // break; // case "beardetails": // animalName = BearData.Bears.ElementAt(rand.Next(0, BearData.Bears.Count)).Name; // break; // case "catdetails": // animalName = CatData.Cats.ElementAt(rand.Next(0, CatData.Cats.Count)).Name; // break; // case "dogdetails": // animalName = DogData.Dogs.ElementAt(rand.Next(0, DogData.Dogs.Count)).Name; // break; // case "elephantdetails": // animalName = ElephantData.Elephants.ElementAt(rand.Next(0, ElephantData.Elephants.Count)).Name; // break; //} if (!string.IsNullOrEmpty(animalName)) { ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?name={animalName}"); Shell.Current.FlyoutIsPresented = false; } }
async Task NavigateToRandomPageAsync() { string destinationRoute = null; int temp = rand.Next(0, 2); string dishName = null; switch (temp) { case 0: destinationRoute = "pizzadetails"; dishName = PizzaData.Pizzas.ElementAt(rand.Next(0, PizzaData.Pizzas.Count)).Name; break; case 1: destinationRoute = "drinksdetails"; dishName = DrinksData.Drinks.ElementAt(rand.Next(0, DrinksData.Drinks.Count)).Name; break; case 2: destinationRoute = "snacksdetails"; dishName = SnacksData.Snacks.ElementAt(rand.Next(0, SnacksData.Snacks.Count)).Name; break; //case "otherdetails": //destinationRoute = "otherdetails"; // dishName = OtherData.Other.ElementAt(rand.Next(0, DrinksData.Drinks.Count)).Name; // break; } ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?name={dishName}"); Shell.Current.FlyoutIsPresented = false; }
/// <summary> /// Navigates to a <see cref="Page"/> passing data to the target ViewModel /// </summary> /// <param name="state"></param> /// <param name="navigationData"></param> /// <param name="animate"></param> /// <returns></returns> public async Task GoToAsync(ShellNavigationState state, object navigationData, bool animate = true) { var isPushed = new TaskCompletionSource <bool>(); Device.BeginInvokeOnMainThread(async() => { try { await Shell.Current.GoToAsync(state, animate).ConfigureAwait(false); isPushed.SetResult(true); } catch (Exception ex) { isPushed.SetException(ex); } }); if (await isPushed.Task.ConfigureAwait(false)) { var presentedViewModel = (Shell.Current?.CurrentItem?.CurrentItem as IShellSectionController)? .PresentedPage.BindingContext; if (presentedViewModel is IOnViewNavigated viewModel) { await viewModel.OnViewNavigatedAsync(navigationData).ConfigureAwait(false); } else { throw new ArgumentException($"You are trying to pass {nameof(navigationData)}" + $" to a ViewModel that doesn't implement {nameof(IOnViewNavigated)}"); } } }
private async void Navigate(object route) { ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{route.ToString()}"); Shell.Current.FlyoutIsPresented = false; }
public override async Task LogoutCommand_Clicked() { try { var logInViewModel = DependencyService.Resolve <Elmah.XamarinForms.ViewModels.LogInViewModel>(); var client = Elmah.MVVMLightViewModels.WebApiClientFactory.CreateAuthenticationApiClientWithToken(); logInViewModel.LoginResponse = await client.LogoutAsync(AppVM.SignInData.UserName); //Framework.Xaml.ApplicationPropertiesHelper.ClearWelcomeWizardData(); //await Framework.Xaml.ApplicationPropertiesHelper.ClearSignInData(); await Framework.Xaml.ApplicationPropertiesHelper.ClearAll(); AppVM.SignInData = new Framework.Xaml.SignInData(); // TODO: should find a solution for this. The current problem is Shell flyout and original not hidden. ShellNavigationState state = Shell.Current.CurrentState; Shell.Current.FlyoutIsPresented = false; Shell.Current.FlyoutBehavior = FlyoutBehavior.Disabled; //AppVM.Caching.DeleteDatabase(); await Shell.Current.Navigation.PushModalAsync(new Elmah.XamarinForms.Pages.LogInPage()); } catch (Exception ex) { } }
protected override async void OnItemSelected(object item) { base.OnItemSelected(item); await Task.Delay(1000); ShellNavigationState state = (App.Current.MainPage as Shell).CurrentState; await Shell.Current.GoToAsync($"{GetNavigationTarget()}?question{((FAQ)item).Question}"); }
public void LocationInitializedWithString() { var uri = new Uri("//test/IMPL_TEST/D_FAULT_TEST", UriKind.Relative); var strState = new ShellNavigationState(uri.ToString()); Assert.AreEqual("//test", strState.Location.ToString()); Assert.AreEqual("//test/IMPL_TEST/D_FAULT_TEST", strState.FullLocation.ToString()); }
///<inheritdoc/> public async Task <object> GoToAsync <TData>(ShellNavigationState state, TData navigationData, bool animate = true) { var viewModel = await InternalGoToAsync(state, animate).ConfigureAwait(false); await RunOnNavigatedsWithDataAsync <TData>(viewModel, navigationData).ConfigureAwait(false); return(viewModel); }
async Task NavigateToRandomPageAsync() { string animalName = null; ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location.AbsoluteUri}?name={animalName}"); Shell.Current.FlyoutIsPresented = false; }
protected override async void OnItemSelected(object item) { base.OnItemSelected(item); await Task.Delay(1000); ShellNavigationState state = (App.Current.MainPage as Shell).CurrentState; //await Shell.Current.GoToAsync($"{GetNavigationTarget()}?model={((Car)item).Model}"); await Shell.Current.GoToAsync($"saledetails?carmodel={((Car)item).Model}"); }
protected override async void OnItemSelected(object item) { base.OnItemSelected(item); await Task.Delay(1000); ShellNavigationState state = (App.Current.MainPage as Shell).CurrentState; // Note: strings will be URL encoded for navigation (e.g. "Blue Monkey" becomes "Blue%20Monkey"). Therefore, decode at the receiver. // This works because route names are unique in this application. await Shell.Current.GoToAsync($"{GetNavigationTarget()}?name={((Grocery)item).Name}"); }
public async Task GoToAsync(ShellNavigationState state, object args = null) { await Shell.GoToAsync(state); var vm = CreateViewModel(state.Location.OriginalString.Split('/').Last()); await Task.Delay(100); // aguardar a pagina carregar CurrentPage.BindingContext = vm; await vm.InitAsync(args).ConfigureAwait(false); }
protected override async void OnItemSelected(object item) { base.OnItemSelected(item); // Let the animation complete await Task.Delay(1000); ShellNavigationState state = (App.Current.MainPage as Shell).CurrentState; // The following route works because route names are unique in this application. await Shell.Current.GoToAsync($"{GetNavigationTarget()}?name={((Animal)item).Name}"); }
private async void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { string eleman = e.SelectedItem.ToString(); // var destinationRoute = (Shell.Current as AppShell).Routes.FirstOrDefault(route => route.Key.Equals("detaylar")).Value; //string aaa = destinationRoute.ToString(); ShellNavigationState state = Shell.Current.CurrentState; string yer = state.Location.ToString(); //string state1 = Shell.Current.CurrentItem.Route; await Shell.Current.GoToAsync($"{state.Location}/detaylar?name={eleman}"); //Shell.Current.FlyoutIsPresented = false; }
protected override async void OnItemSelected(object item) { base.OnItemSelected(item); // work around for bug 5713 // https://github.com/xamarin/Xamarin.Forms/issues/5713 await Task.Delay(400); ShellNavigationState state = (App.Current.MainPage as Shell).CurrentState; await Shell.Current.GoToAsync($"{GetNavigationTarget()}?ItemId={((Person)item).Id}"); }
// https://stackoverflow.com/questions/57554375/xamarin-forms-4-shell-navigation-with-complex-parameters public static async Task GoToAsync(this Shell shell, ShellNavigationState state, object navigationData, bool animate = false) { // https://stackoverflow.com/questions/2051357/adding-and-removing-anonymous-event-handler/30763657 void handler(object sender, EventArgs e) { ((Shell.Current?.CurrentItem?.CurrentItem as IShellSectionController)?.PresentedPage as IPageNavigate)?.OnPageNavigated(navigationData); shell.Navigated -= handler; } shell.Navigated += handler; await shell.GoToAsync(state, animate); }
private async void ImageOnClicked(object sender, EventArgs e) { var btn = sender as ImageButton; var cocktail = btn?.CommandParameter as Cocktail; ShellNavigationState state = Shell.Current.CurrentState; if (cocktail != null) { await Shell.Current.GoToAsync($"{state.Location}/random?name={cocktail.StrDrink}"); Shell.Current.FlyoutIsPresented = false; } }
protected override async void OnItemSelected(object item) { base.OnItemSelected(item); // Let the animation complete await Task.Delay(1000); ShellNavigationState state = (App.Current.MainPage as Shell).CurrentState; // The following route works because route names are unique in this application. var JsonData = JsonConvert.SerializeObject(item); var route = $"{nameof(FamilyDetailsPage)}?Family={JsonData}"; await Shell.Current.GoToAsync(route); }
protected override async void OnItemSelected(object item) { //base.OnItemSelected(item); var eleman = (Notlar)item; string parametre = eleman.Detay; await Task.Delay(1000); ShellNavigationState state = Shell.Current.CurrentState; //string yer = state.Location.ToString(); //string state1 = Shell.Current.CurrentItem.Route; await Shell.Current.GoToAsync($"{state.Location}/detaylar?name={parametre}"); //await Shell.Current.GoToAsync($"detaylar?name={parametre}"); // The full route is shown below. // await Shell.Current.GoToAsync($"//animals/monkeys/monkeydetails?name={((Animal)item).Name}"); }
async Task NavigateToRandomPageAsync1() { string destinationRoute = routes.ElementAt(rand.Next(0, routes.Count)).Key; string XXNazov1 = null; switch (destinationRoute) { case "priznakydetails": XXNazov1 = Symptom.Symps.ElementAt(rand.Next(0, Symptom.Symps.Count)).Nazov_Symptom; break; } ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?nazov_Symptom={XXNazov1}"); Shell.Current.FlyoutIsPresented = false; }
async Task NavigateToRandomPageAsync() { string destinationRoute = routes.ElementAt(rand.Next(0, routes.Count)).Key; string XXNazov = null; switch (destinationRoute) { case "vitaminydetails": XXNazov = Zoznam.Zoznams.ElementAt(rand.Next(0, Zoznam.Zoznams.Count)).Nazov; break; } ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?nazov={XXNazov}"); Shell.Current.FlyoutIsPresented = false; }
//随机 async Task NavigateToRandomPageAsync() { string destinationRoute = routes.ElementAt(rand.Next(0, routes.Count)).Key; string animalName = null; switch (destinationRoute) { case "catdetails": animalName = CatData.Cats.ElementAt(rand.Next(0, CatData.Cats.Count)).Name; break; } ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?name={animalName}"); Shell.Current.FlyoutIsPresented = false; }
public static async Task NavigateAsync(string pageName, Dictionary <string, object> parameters = null) { AppShellVM.Cleanup(); ShellNavigationState state = Shell.Current.CurrentState; if (parameters == null || parameters.Count == 0) { await Shell.Current.GoToAsync(string.Format("{0}", pageName)); } else { var parametersQuery = from t in parameters select string.Format("{0}={1}", t.Key, t.Value); var parametersInString = string.Join("&", parametersQuery); await Shell.Current.GoToAsync(string.Format("{0}?{1}", pageName, parametersInString)); } Shell.Current.FlyoutIsPresented = false; }
async Task NavigateToRandomPageAsync() { string destinationRoute = routes.ElementAt(rand.Next(0, routes.Count)).Key; string groceryName = null; switch (destinationRoute) { case "fruitdetails": groceryName = FruitData.Fruits.ElementAt(rand.Next(0, FruitData.Fruits.Count)).Name; break; case "vegetabledetails": groceryName = FruitData.Fruits.ElementAt(rand.Next(0, VegetableData.Vegetables.Count)).Name; break; } ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?name={groceryName}"); Shell.Current.FlyoutIsPresented = false; }
private Task <object> InternalGoToAsync(ShellNavigationState state, bool animate = true) { var isPushed = new TaskCompletionSource <object>(); Device.BeginInvokeOnMainThread(async() => { try { await Shell.Current.GoToAsync(state, animate).ConfigureAwait(false); var viewModel = (Shell.Current?.CurrentItem?.CurrentItem as IShellSectionController)? .PresentedPage .BindingContext; await RunOnNavigatedsAsync(viewModel).ConfigureAwait(false); isPushed.SetResult(viewModel); } catch (Exception ex) { isPushed.SetException(ex); } }); return(isPushed.Task); }
async Task NavigateToRandomPageAsync() { string destinationRoute = routes.ElementAt(rand.Next(0, routes.Count)).Key; string cloudName = null; switch (destinationRoute) { case "cloudeuadetails": cloudName = await DataCloud.GetRandomCloudsAsync(); break; case "cloudchinadetails": cloudName = await DataCloud.GetRandomCloudsAsync("1"); break; } ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?name={cloudName}"); Shell.Current.FlyoutIsPresented = false; }
async Task NavigateToRandomPageAsync() { string destinationRoute = routes.ElementAt(rand.Next(0, routes.Count)).Key; string animalName = null; switch (destinationRoute) { case "monkeydetails": animalName = MonkeyData.Monkeys.ElementAt(rand.Next(0, MonkeyData.Monkeys.Count)).Name; break; case "beardetails": animalName = BearData.Bears.ElementAt(rand.Next(0, BearData.Bears.Count)).Name; break; case "catdetails": animalName = CatData.Cats.ElementAt(rand.Next(0, CatData.Cats.Count)).Name; break; case "dogdetails": animalName = DogData.Dogs.ElementAt(rand.Next(0, DogData.Dogs.Count)).Name; break; case "elephantdetails": animalName = ElephantData.Elephants.ElementAt(rand.Next(0, ElephantData.Elephants.Count)).Name; break; case "lessondetails": animalName = LessonData.Lessons.ElementAt(rand.Next(0, LessonData.Lessons.Count)).Name; break; } ShellNavigationState state = Shell.Current.CurrentState; await Shell.Current.GoToAsync($"{state.Location}/{destinationRoute}?name={animalName}"); Shell.Current.FlyoutIsPresented = false; }
/// <summary> /// Navigates to a <see cref="Page"/> passing data to the target ViewModel /// </summary> /// <param name="state"></param> public Task GoToAsync(ShellNavigationState state) { return(GoToAsync(state, true)); }
///<inheritdoc/> public Task <object> GoToAsync(ShellNavigationState state, bool animate = true) => InternalGoToAsync(state, animate);
/// <summary> /// Navigates to a <see cref="Page"/> /// </summary> /// <param name="state">A URI representing either the current page or a destination for navigation in a Shell application.</param> /// <param name="animate"></param> /// <returns></returns> public Task GoToAsync(ShellNavigationState state, bool animate = true) { return(GoToAsync(state, null, animate)); }