Navigation page not showing back arrow in Prism.Forms Unity Application? - c#

I am using the Prism.Forms.Unity
On drawer menu item selected user is navigating from MasterDetails page to next page, On the navigated page is not showing me that back arrow which will go back to my master details page.
I have tried using few options which are shown below
The first option I tried using the NavigationPage, starting the new page using prism navigation method
_navigationService.NavigateAsync("NavigationPage/Add");
The second option I tried to set the property in XAML
NavigationPage.HasBackButton="True"
These two ways are not working for me.
What is the correct way to this?

There is no back button if you only have one page on the NavigationPage's navigation stack. You need to have more than one page on the nav stack to have a back button. Otherwise, there is nothing to go back to.

Related

Open new page outside masterdetailpage

I just new to Xamarin.Form with Prism. I want to load the page in different behavior. The first one I achieve already is in image below.
But I want to do a behavior like below image. Load a new page outside master detail page. How can I do it in prism?
You have figured out how to display the "Hamburger" icon as well as title by doing the following.
NavigationService.NavigateAsync("MasterPage/NavigationPage/DetailsPage")
If a user makes a selection from the actions listed on the master page. For Example, let's say settings.
You have a couple of options here, you can do navigate relatively
NavigationService.NavigateAsync("Settings")
This will navigate to the settings page. This will also display the back button as the second image. Your current page path will be
MasterPage/NavigationPage/DetailsPage/Settings
Now let's say you want the settings page to be the top details page. You have to navigate to it via an absolute path.
MasterPage/NavigationPage/Settings
NavigationService.NavigateAsync("MasterPage/NavigationPage/Settings")
You need to add a new page to the stack, page over existing one. To do that you should do navigation like this:
navigationService.NavigateAsync("Settings")

Back button functionality c#

Currently I'm in say Page A. The URL is http://localhost:22507/PageA.aspx. From there select a dropdown value. Now the same page shows some extra data and an edit button along with the dropdown. Page URL is still http://localhost:22507/PageA.aspx. When I click the Edit button its redirected to another page Page B. And the present URL is http://localhost:22507/PageB.aspx?qstr=6EysKHDt1+a/m8SQcruQOCVgWF+9+PCfmydyeX5wbKU=
While clicking the Back button in the Page B, it directly goes to the first state. ie, I've to again select the drop down, click edit etc.
How can I go back to the just previous state(Page A with data and Edit button) after clicking Back button?
Now I use Response.Redirect("PageA.aspx", false); for redirecting
When changing the selected list item, use pushState to update the browser address bar and history to record the change of state. E.g instead of the address bar still displaying /PageA.aspx, it could instead show /PageA.aspx?selected=1.
If you then use the back button from PageB.aspx?qstr=6EysKHDt1+a/m8SQcruQOCVgWF+9+PCfmydyeX5wbKU=, pressing back will return you to PageA.aspx?selected=1. You can then parse the query string to determine the correct state to display.
Mozilla provides documentation on pushState here: https://developer.mozilla.org/en-US/docs/Web/API/History_API.
Note that for older browsers there are some compatibility issues. A clunky old method that would work would be to reload the page with a query string when the dropdown is changed, allowing the back button to work in much the same way. An alternative that avoids reloading the page may be to update a cookie with a flag indicating the state. On loading the page, check for the cookie and flag. However, then you would need to consider expiry of the cookie (ie what if they didn't press back but instead navigated to pageA again through some other means, would loading the saved state still be acceptable?).

How to store state in Windows 8.1 using Blank Page Template?

I am migrating my Windows Phone 8 App to Windows 8.1 App and I have created a Page with blank page template. In that there are some Items like TextBlock,ComboBox and TextBox. Now, there is an item LocationTextBlock with border around it. When I click on it, it navigates to a new Page LocationPage, where I need to select location and save that object and navigate using Frame.GoBack() method. Now the issue, when I navigate back, I get the object of LocationData but the LocationTextBlock which was created previously is showing null, so I can't populate Location in that TextBlock.
Questions
Is this issue occurring due to Blank Page Template ?
Can it be solved using NavigationHelper Class?
Will using Basic Page Template resolve this issue?
Please suggest with some code or description, whether it can be done using Blank Page template as I have added many lines of code inside it.
It can be done with Blank Page template (although using NavigationHelper would be the prefered way).
What you have to do is set NavigationCacheMode to Enabled in your Page's Constructor:
this.NavigationCacheMode = NavigationCacheMode.Enabled;
This way the Page with all the properties in it is cached. So when you navigate back you get back the state in which the Page was when you navigated from it. However, if you navigate to this page not through backnavigation, you'll still get back the saved state, which you don't want. The solution is to clean up all the resources (initializing the needed variables, setting UI elements to default value etc.) in the OnNavigatedTo(NavigationEventArgs e) method if (e.NavigationMode != NavigationMode.Back). Don't know if it's the best approach, but it'll work.
EDIT:
You could even use a Flyout or a ContentDialog instead of your LocationPage, so you don't need to navigate from the page, thus not needing to cache/save the page.

Windows Phone 8 Databound App and back button

I've something that I can't get myself understand. I'm making an app with databound template. I put a textbox on mainpage and a button. when i type something in textbox and press on button it navigates to the listing page and that content comes from web and then if i press on back button and make a new search the results from previous search stays there. how can i reset/clear or disable cache of that page?
It would be helpful if you could post your XAML and code-behind, but I will attempt to make a jab at an answer. Where are you referencing the call to get the data from the web? If it is in the constructor of the page, then that is why the previous search stays there. What is probably happening is the first search constructs the secondary page, does your web call, and binds your data to the page. Then when you press the back button, and click it again, the page is already constructed, so it uses the same data.
It is probably wise to call your web service in the OnNavigatedTo override method. From the first page, you can pass parameters to your secondary page (i.e., pass the search term, then pass the search term into your web service).
Here is an example of passing parameters between pages: http://developer.nokia.com/Community/Wiki/Passing_parameters_while_navigating_between_pages_on_Windows_Phone
Also, make sure your Data Context for the second page is appropriately set each time the page is navigated to, since you have a data bound application.
Without code, I can't really help other than giving these things to think about.

Reload a Web Page Using C#

I have a web page that prompts for user input via DropDownLists in some table cells. When a selection is made the selection replaces the DropDownList so that the action can only be performed once. In the case that a change needs to be made I want to be able to click a button that reloads the page from scratch. I have Googled and Googled but I have not managed to find a way to do this.
Any advice is appreciated.
Regards.
Put a link on the page with the text "Reload" and the url the url of the page. It's perfectly valid to have a page with a link to itself.
If you don't like the link idea, use a standard Button and in the click event, use Response.Redirect to redirect to the current page.
You can set an OnClick for your button that resets each DropDownList's SelectedIndex to 0 instead of reloading the page from scratch. Alternatively, you can set a Response.Redirect([the page's url]) into the OnClick as is suggested here.

Categories

Resources