public bool NavigateToTestPage(string test) { try { // Create an instance of the main page var root = CreateDefaultMainPage(); // Set up a delegate to handle the navigation to the test page EventHandler toTestPage = null; toTestPage = delegate(object sender, EventArgs e) { Current.MainPage.Navigation.PushModalAsync(TestCases.GetTestCases()); TestCases.TestCaseScreen.PageToAction[test](); Current.MainPage.Appearing -= toTestPage; }; // And set that delegate to run once the main page appears root.Appearing += toTestPage; SetMainPage(root); return(true); } catch (Exception ex) { Log.Warning("UITests", $"Error attempting to navigate directly to {test}: {ex}"); } return(false); }
public CoreRootPage(Page rootPage, NavigationBehavior navigationBehavior = NavigationBehavior.PushAsync) { ValidateRegistrar(); IStringProvider stringProvider = DependencyService.Get <IStringProvider>(); Title = stringProvider.CoreGalleryTitle; var corePageView = new CorePageView(rootPage, navigationBehavior); var searchBar = new SearchBar() { AutomationId = "SearchBar" }; var testCasesButton = new Button { Text = "Go to Test Cases", AutomationId = "GoToTestButton", Command = new Command(async() => { if (!string.IsNullOrEmpty(searchBar.Text)) { await corePageView.PushPage(searchBar.Text); } else { await Navigation.PushModalAsync(TestCases.GetTestCases()); } }) }; var stackLayout = new StackLayout() { Children = { testCasesButton, searchBar, new Button { Text = "Click to Force GC", Command = new Command(() => { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); }) } } }; Content = new AbsoluteLayout { Children = { { new CoreRootView(), new Rectangle(0, 0.0, 1, 0.35), AbsoluteLayoutFlags.All }, { stackLayout, new Rectangle(0, 0.5, 1, 0.30), AbsoluteLayoutFlags.All }, { corePageView, new Rectangle(0, 1.0, 1.0, 0.35), AbsoluteLayoutFlags.All }, } }; }