Xamarin Tabbed Page Content Other than Tab - c#

Quick question,
In Xamarin Forms, when using a Tabbed Page, is there any way for there to be content that remains static between the tabs (other than the tabbar itself)?
For example, if I have a TabbedPage with 3 children (say Page1, Page2 and Page3), can I add other children to TabbedPage that are not a part of the tab itself, but elsewhere, and stay there between tabs?
My use for this is I have 3 tabs in my TabbedPage, which is are at the bottom of the page. I would like a settings button in the top-right of each page, without having to create the same content multiple times in each page that is a child of the TabbedPage.
<TabbedPage xlmns="...>
[Content Here that remains between all tabs, but not a part of the tabbar itself]
<local:Page1>
<local:Page2>
<local:Page3>
</TabbedPage>
Is there some way of doing this easily? Or is there some other method?
Thanks for any help.

You need to check this and create your own control template
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/control-templates/

I would like a settings button in the top-right of each page, without having to create the same content multiple times in each page that is a child of the TabbedPage.
An easy way is using custom control as model. Add the custom control, the button would show in every tabbed pages(page1, page2, page3). If you want to more change on the button, change the custom model, all the changes would show in pages.
Custom Control: ButtonModel
<Button x:Name="btnModel" Text="Button" HorizontalOptions="EndAndExpand" Margin="4,0,8,0"></Button>
Add this in Page1, Page2, Page3
<local:ButtonModel ></local:ButtonModel>

There are a few methods of fixing this. One of these is outlined in another comment very well, however I found that the Xamarin Forms 'Pure' tabs fitted my needs better.
https://www.sharpnado.com/pure-xamarin-forms-tabs/
It was relatively intuitive once I got my head round it and handles integration with mvvm rather well. The tabs need nod span the entire page (other than the tabbar) which is exactly what I wanted.

Related

Xamarin Shell hierarchy with child page

I have specified a trival page structure in a Xamarin Shell v5 app. I have a flyout with flyout items in the following structure:
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<ShellContent>
<local:MainPage...
</ShellContent>
<ShellContent>
<local:Page1...
</ShellContent>
<ShellContent>
<local:Page2...
</ShellContent>
</FlyoutItem>
When I start the app the MainPage is displayed as default. So far so good.
The flyout displays the three pages. Also good.
When I tap on the Page2 flyout, that page is displayed. But a navigation stack isn't created, meaning it also displays the hamburger menu (instead of the back button where the hamburger icon is).
I would like to have Page2 be a "child page" (navigation-wise) so that when a user taps the Page2 flyout a back button is displayed at the top so the user can go back to the Homepage.
I've been reading the documentation backwards and forwards, and can't figure out how to do this in the visual shell hierarchy.
I assume it has to do with routes, but I'm not sure how to specify routes so Page2 becomes a 'sub-page' (or whatever the word is).
Does anyone know how to do this? This applies to both iOS and Android.
I would prefer not to have the tabs displayed at the bottom of the screen as I've seen in many examples. Just a neat, clean flyout menut.
If the pages are still in the Shell hierachical structure(the page2 in the FlyoutItem), the hamburger icon would show always.
You could use the code below to register the pages that do not exist in the Shell visual hierachy. And then when you navigate to these pages, you could use the back button to go back.
Routing.RegisterRoute("page2", typeof(Pages));
Navigate:
await Shell.Current.GoToAsync("page2");
In the end I solved it by using MenuItems instead of FlyoutItems. In the callback for each MenuItem I call Shell.Current.GoToAsync(""); which opens the page as a child, i.e. back navigation can be performed.
And since menu items can be styled (just like flyout items), it looks nice on the device. It's a workaround, but one I'm happy with.

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")

A Page without the tab Xamarin.forms

I want a specific page without the tabbed page. I want to remove the tabbed page. However when I use this code it removes the navigation.
NavigationPage.SetHasNavigationBar(this, false);
Based on this link from Xamarin:
It seems you need to create a custom renderer for your page and set ParentViewController.TabBarController.TabBar.Hidden = true in ViewWillAppear()

Does the form tag in a .NET page belong in the Master page or the usercontrol?

In the early days of .NET, you had no choice. Your entire page content was wrapped in a single form tag and you made it work. Somewhere along the way, we started moving away from that, however where I read it eludes me. I recall reading that the new standard is not to put a single form tag in your master page and instead place the form tag in each usercontrol that needed it.
This worked well for me up until recently. I've now created a usercontrol that works fine if the form tag is in the Master page, but if the form control is in the usercontrol, when the form postsback, none of the controls retain their preselected values (i.e. my dropdownlist selection).
Should I go back to placing my form control in the Master page and strip the form tag out of all of my usercontrols? Or did I read correctly and the new recommendation is to put form tags in usercontrols?
If you are using ASP.NET web forms you should have the form tag in the master page.
See this link:
http://msdn.microsoft.com/en-us/library/fb3w5b53%28v=vs.100%29.aspx
From this article:
The user control does not have html, body, or form elements in it. These elements must be in the hosting page.

Can you change a master page's ContentPlaceHolder's Content Page Asynchronously in .NET?

From what I've already read this appears to be impossible, but I wanted to see if anyone out there has a secret trick up their sleeve or at least a definitive "no".
Supposedly a master page is really just a control for a content page to use, not actually the "master" of a content page. If I wanted to go from one content page, to another content page with the same master page, I would just say
Response.Redirect("PageB.aspx");
But this would immediately cause a postback, flickering the page, which is the crappy pre-ajax way of doing things.
In this current project, I'm trying to see if I could figure out how to change the current content page of a ContentPlaceHolder in the master page asynchronously, when a button is clicked on the master page.
Is this possible, if so how?
I don't know if you can between pages (.aspx) but it can definitely be done using UserControls.
ASP.Net pages each have their own URL so what you're trying to do is to go from one URL to another without any postback, that's just not how it's supposed to work.
Using user controls (.ascx):
Create a page that uses the MasterPage and use something like this in the content
<ajax:UpdatePanel ...>
<ContentTemplate>
<asp:PlaceHolder ...>
</ContentTemplate>
</ajax:UpdatePanel>
Search for UpdatePanel and tweak its settings to do what you want, then learn how to swap user controls in a placeholder.
No, you cannot because a master page is actually a control rendered on a particular aspx page, rather than actually containing the aspx page as it deceptively appears to be programmatically and in design view.
More Info:
You could however use a variety of other controls to simulate this effect. The asp:MultiView control is one example, each "page" could be made in a single view and placed in an update panel, thus allowing it to be switched asynchronously. Alternatively you could define each page in a separate user control and put those in an update panel, asynchronously switching the visible property on those controls as needed.
There are really a lot of different ways to achieve an effect similar to changing the master page's content placeholder.

Categories

Resources