Xamarin Navigation Issue on Back - xamarin

I've three pages first showing List of my items on tap I'm redirecting it to a History Page with Object defined with static property with
await Shell.Current.GoToAsync($"/{nameof(DeviceHistoryPage)}");
then from this page i'm again redirecting user to show more details of each history item to next page with data as static property
await Shell.Current.GoToAsync($"/{nameof(DeviceHistoryDetailsPage)}");
I'm able to achieve this navigation and able to move back and forth from first page to second page but from second page once redirected to third page and i'm not able return back to previous page with back button present in navbar
Also I've tried registering routes as independent as well as a child in AppShell as follows
Routing.RegisterRoute($"{nameof(ListPage)}/{nameof(HistoryPage)}", typeof(HistoryPage));
Routing.RegisterRoute($"{nameof(HistoryPage)}/{nameof(HistoryDetailsPage)}", typeof(HistoryDetailsPage));

Related

How to pass data from one page model to another page model in fresh mvmm

I have used Fresh MVMM. I need to pass a data from one page model to another page model without using init and reverse init.
Eg: I have one toggle button in first content page.
I need to toggled the button based on the selection in second popup page without popup the second PopPopupPageModel.
ReverseInit is worked when popup the second PopPopupPageModel and can easily pass data.
But I need to toogled the button in first page without popup the second page.
Please help...

Xamarin Forms: Values vanished/refreshed on swiping more than four content pages inside carousel page or tabbed page

I am working on a xamarin forms project which have a carousel page container, and content pages as its children are created dynamically on different condition checks. (Minimum 8 children in my case)
Let's take the mentioned minimum case. I enter some values in entry/picker controls in the 1st child and then navigate/swipe pages till 5th child. When I came back to the first child page, the values I entered/selected are now vanished/refreshed.
I have noticed that carousel page saves only 3 pages data in it. i.e. (Left Page, Current Page and the Right Page).
And Tabbed page saves 4 pages data.
I want the values to stay in the child page where I entered whether I navigate to the last most page or in the middle and navigate back to that page.
I have googled via the letters as "Carousel page/ Tabbed page Saved states" etc. but unable to find something useful.
So, I need to know the property name/ method name etc. by which xamarin forms setting the limit of carousel page as 3 and tabbed page as 4.
Waiting for your response.
Thanks.
OK I found that I was using a Custom Picker Control and the value refreshing issue is with it. I just forget to set the selectedIndex of the picker on OnElementChanged event.

Page 'loaded' event behavior explanation - difference between navigateTo() and goBack()

I've got an app with a page xml definition that has a grid-layout with no children. During the page 'loaded' event, I create a bunch of child elements and add them to the grid-layout dynamically.
I navigate to another page and then call frameModule.topmost().goBack() to go back to the previous page.
On that main page, the 'loaded' event gets called again - BUT has the children I already added in the previous navigation - so looks like the page wasn't created again.
Interestingly, if from the same main page, I navigate to another page and then navigate back (i.e. w/o calling goBack()), then the 'loaded' event gets called but the page doesn't have the children I added - so looks like the page was freshly created.
My questions are:
When one calls goBack(), why is 'loaded' called on the previous page - even though it looks like the previously loaded page was being used.
Is this a bug?
Any way to determine in the 'loaded' function - whether this is truly a fresh page loaded or all elements have been created.
The major difference between goBack and Navigate is that goback just goes back up the navigation history stack, and acts the same as if the person hits the "back" button(android) or swipes to the right (iOS). Navigate goes forward and adds a new stack entry that you can goBack on.
Lets look at two examples:
So if I started on Page1 and Navigated to Page2, then Navigated to Page3 then the user hit my "< Back" button and in the code I then Navigated To Page1, my Navigation Stack would look like this:
Page1
Page2
Page3
Page1
If I then use the hardware back button (which triggers) goBack it will be Page3, then Page2, then Page1. The user would probably not expect being on Page1 and hitting the back button to put them on Page3 rather than exiting. So unless you are wanting a weird navigation; this would be normally considered unexpected/broken behavior.
Under proper navigation I might do this:
Page1
Page2 (Not stored in History: used "backstackVisible: false")
Page3
Then a Back from Page3 would actually put me in Page1, and a Back from Page 1 would exit the application. This would be the expected behavior.
Now as to the events.
The events for this page are NavigatingTo, Loaded, NavigatedTo -- they fire in that order.
The loaded event being called is not a bug; it is by design; when the page component is loaded -- it allows you to be able to set up the page element. All components have a "loaded" event. So this is a component level event not a page navigation type event. So for example; I've done this before:
<Switch android:loaded="fixAndroidSwitch"/> and then my fixAndroidSwitch routine fixed up something on the switch.
The NavigatingTo and NavigatedTo are actual Navigation events, and they do have a value passed as part of the argument:
function onNavigatingTo(context) {
if (context.isBackNavigation) { /* Do whatever */ }
}
For more information on page events; you can read my Blog post http://fluentreports.com/blog/?p=191 and it explains more

navigate back and display the previous page without reloading the previous page variables and designs?

I have one issue in my program, i have three pages in my program, Main page, first page and second page. I'm able to navigate from the main page to the first page and from the first page to the second page. I have a stack panel in the first page. It consists of children which are dynamically created from the db. This page contains a OnNavigateTo method, for bringing the elements from the main page and displaying it, And i wrote my codings in this method to add dynamically children to the stackpanel. when navigating back from the second page to the first page, the compiler will goes to the OnNavigateTo method and regenerate the children of the stackpanel once again.
My problem is:
i want to show the previously displayed first page with all the data, when the back button is pressed. I doesn't want the page to regenerate again. I want the static page which i have previously when i go back from the second page to the first page.
How to do it? please help me with some piece of code... Thank You..
Do the logic in the constructor, because it doesn't get called when navigating back (unless the app has been tombstoned). OnNavigatedTo gets called every time no matter how you navigate to the page.
Read this for more info:
WP7 Development Tip of the Day: Page Startup: The Constructor

MVC3 Navigation, browser positionin g

I have a C#.NET MVC3 web app. I have a View that has a List of Models. This list can be long, requiring the user to scroll down on the View. When selecting one of the models in the View to Edit, the user is taken to the Edit View. After submitting the Edit View, the user is redirected back to the List View. However, the List View is now displaying back at the top of the list. How can I redirect the user back to the same position in the List View where they clicked the Edit button?
You would probably be better suited using a modal popup dialog to edit the data, rather than navigating to another page.
While it's possible to do what you want, it's a pain. You would have to get the scroll location via javascript, save it to a hidden field, post that to your edit page, along with record number and anything else, then re-post it back to your original page when you return, then read the post value and scroll to it via javascript.
All that is avoided if you just use a modal edit dialog, then when the dialog goes away the page is still in the same place.

Resources