private T GetElementFromRouting <T>(string routeWithParams) where T : Element { var routeAndParams = routeWithParams.Split('?'); if (routeAndParams.Length > 1) { var routeName = routeAndParams.FirstOrDefault(); var query = routeAndParams.LastOrDefault(); var queryData = ParseQueryString(query); var page = (T)Routing.GetOrCreateContent(routeName); var attrs = (QueryPropertyAttribute[])Attribute.GetCustomAttributes( page.GetType(), typeof(QueryPropertyAttribute)); if (attrs != null && attrs.Length > 0) { foreach (var attr in attrs) { queryData.TryGetValue(attr.QueryId, out var value); var prop = page .GetType() .GetProperty(attr.Name, BindingFlags.Public | BindingFlags.Instance); if (null != prop && prop.CanWrite) { prop.SetValue(page, value, null); } } } return(page); } else { return((T)Routing.GetOrCreateContent(routeWithParams)); } }
public async Task CaseIgnoreRouting() { var routes = new[] { "Tab1", "TAB2", "@-_-@", "+:~", "=%", "Super_Simple+-Route.doc", "1/2", @"1\2/3", "app://tab" }; var services = Substitute.For <IServiceProvider>(); foreach (var route in routes) { var formattedRoute = Routing.FormatRoute(route); Routing.RegisterRoute(formattedRoute, typeof(ShellItem)); var content1 = Routing.GetOrCreateContent(formattedRoute, services); Assert.IsNotNull(content1); Assert.AreEqual(Routing.GetRoute(content1), formattedRoute); } Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute("app://IMPL_tab21", typeof(ShellItem))); Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute(@"app:\\IMPL_tab21", typeof(ShellItem))); Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute(string.Empty, typeof(ShellItem))); Assert.Catch(typeof(ArgumentNullException), () => Routing.RegisterRoute(null, typeof(ShellItem))); Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute("tab1/IMPL_tab11", typeof(ShellItem))); Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute("IMPL_shell", typeof(ShellItem))); Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute("app://tab2/IMPL_tab21", typeof(ShellItem))); }
public static Task GoToModalAsync(this Shell shell, string route) { var page = Routing.GetOrCreateContent(route) as Page; if (page is null) { return(Task.CompletedTask); } return(shell.Navigation.PushModalAsync(new NavigationPage(page) { BarBackgroundColor = Color.Transparent })); }
// https://forums.xamarin.com/discussion/168512/shell-showing-modal-pages public static Task GoToModalAsync(this Shell shell, string route, object navigationData, bool animate = false, EventHandler onOK = null) { var page = Routing.GetOrCreateContent(route) as Page; if (page is null) { return(Task.CompletedTask); } page.BindingContext = navigationData; if (page is IPageOK iPage) { iPage.OnOK += onOK; } return(shell.Navigation.PushModalAsync(new NavigationPage(page), animate)); }
public static Task GoToModalAsync(this Shell shell, string route) { try { if (!(Routing.GetOrCreateContent(route) is Page page)) { return(Task.CompletedTask); } return(shell.Navigation.PushModalAsync(new NavigationPage(page) { BarBackgroundColor = Color.Transparent })); } catch (Exception ex) { var exception = new NavigationException($"Navigation to route {route} failed. ", ex); logger.Error(exception); throw exception; } }
public void DetermineAndSetMainPage(string mainRouteName) => Application.Current.MainPage = (Shell)Routing.GetOrCreateContent(mainRouteName);
async Task HandleAddItemAsync() { await Shell.Current.Navigation.PushModalAsync(Routing.GetOrCreateContent("new") as ContentPage); }
public Element GetOrCreateContent(string route) { return(Routing.GetOrCreateContent(route)); }
public Task NavigateToPageAsync(string routeWithParams, bool animated = true) => Application.Current.MainPage.Navigation.PushAsync( (Page)Routing.GetOrCreateContent(routeWithParams), animated);