Like in Windows Forms we can add multiple panels in the same Form and based on some condition show and hide particular panel. Is there any control in Xamarin.Forms
which can be used like this?
The main reason behind this is, I have 3 tabs on a page. I am using buttons for tabs and not tabbed pages as design of tabbed bar is not what my client wants. So I have 3 pages say Page A
, Page B
, Page C
and each of the page has 3 tabs to go to respective page. If user is on Page A
and fills some sort of data(which is not yet saved) and wants to go to Page B
and then on Page B
he fills in some more details and then without saving data on Page B
when he comes back to Page A
all the details filled by user on Page A
and Page B
has to be available.
Hence If I use multiple pages for this then the data will be lost when I redirect to new page. So Is there any way by which I have multiple panels and hide 1st panel when 2nd panel is visible which will not clear any data and hence I can achieve what I want.
You can just hide the panels that aren't being used (using the
IsVisible
property) - this pulls them out of the visual tree but does not release them from memory.If you create a Content View for each page, then you can easily use them in your main UI such as in this example. Even though we are hiding the individual panels they will still remain in memory while hidden:
MyView.cs (this could be anything you want in your panels):
XamlPage.xaml (main UI page):
XamlPage.xaml.cs:
You can save this data to a cache and load it from there.
But be aware: It's just a memory cache. If the App gets tombstoned, the data will be lost. You can try this approach first and see if its fits your need. After that, you should store the data in a temporary storage (e.g. with Akavache). You should not rebuild this page navigation behavior with something custom.