locked
Navigate back to previous page. RRS feed

  • Question

  • User320662 posted

    Hi Guys,

    I'm currenly experimenting with Xamarin forms, I'm having trouble navigating from webView back to previous menu.

         public void ButtonName(object sender, EventArgs args)
         {
            var browser = new WebView();
            browser.Source = "websiteURL";
            Content = browser;
    }
    

    I have this for my button which loads a website, but once on this page I cannot nav back to the menu. I tried adding a button on the navbar like so;

    ToolbarItems.Add(new ToolbarItem
                {
                    Name = "Done",
                    Command = new Command(() => Navigation.PopAsync()),
                });
    

    But have had no luck. I'm extremely new to Coding in C# so some tips would be great!

    Tuesday, June 13, 2017 8:55 AM

Answers

  • User102046 posted

    @Devv i am not sure about one thing is the webview on the same page or is it on the separate page. like one page 1 you have a button when u click on that , you go to 2nd page which has the webview and in the navigation bar you have a button with text "Done". when you are clicking it it is not navigating back? are you navigating to 2nd page Via await navigation.pushAsync(PageInstance)?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 13, 2017 9:06 AM
  • User89714 posted

    @Devv - From the tiny piece of code shown, my suspicion is the same as what @Xami3 has said - that you are not creating a second page at all. Instead, you are changing the content of the first page to be a WebView. That's why attempting to pop the page does not do what you expect.

    For the second page, create a new class that inherits from ContentPage and put the WebView in that page. In the button handler for the first page, use

    await Navigation.PushAsync(secondPageInstance);
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 13, 2017 9:16 AM

All replies

  • User102046 posted

    @Devv i am not sure about one thing is the webview on the same page or is it on the separate page. like one page 1 you have a button when u click on that , you go to 2nd page which has the webview and in the navigation bar you have a button with text "Done". when you are clicking it it is not navigating back? are you navigating to 2nd page Via await navigation.pushAsync(PageInstance)?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 13, 2017 9:06 AM
  • User320662 posted

    Menu Page > Click Button > Website Load in App

    I'm not sure if there is a way to force it to load the Menu Page againwhen clicking 'Done'. Menu on Left - WebView on Right. (I've removed the page it loads for screenshot.)

    Tuesday, June 13, 2017 9:10 AM
  • User89714 posted

    @Devv - From the tiny piece of code shown, my suspicion is the same as what @Xami3 has said - that you are not creating a second page at all. Instead, you are changing the content of the first page to be a WebView. That's why attempting to pop the page does not do what you expect.

    For the second page, create a new class that inherits from ContentPage and put the WebView in that page. In the button handler for the first page, use

    await Navigation.PushAsync(secondPageInstance);
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 13, 2017 9:16 AM
  • User102046 posted

    @Devv can you upload a test project here, which we can look into like what are you doing right now and where might be the problem? i am using these navigation alot and believe me there is nothing wrong except when we do something wrong.

    Tuesday, June 13, 2017 9:22 AM
  • User320662 posted

    Thank you so much guys! - I created the new page and loaded the content through that instead of being silly and over-righting my current page.

    Tuesday, June 13, 2017 9:25 AM
  • User102046 posted

    @Devv Great :)

    Tuesday, June 13, 2017 9:32 AM