I am trying to remove navbar from my pages in Xamarin Forms, but I am not able to get it working. I have tried by adding NavigationPage.SetHasNavigationBar(this, false); inside constructor of page eg.
public RegisterUser ()
{
InitializeComponent ();
NavigationPage.SetHasNavigationBar(this, false);
}
And / or by adding NavigationPage.HasNavigationBar="False" inside xaml page
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PetApp.Pages.RegisterUser"
NavigationPage.HasNavigationBar="false">
But none of those helps.
Is there some better best practice to just show clean page with scrollview or should it be possible to remove navbar totally?
It works in Mainpage but not the rest of pages that I am navigating to via
await Navigation.PushAsync(new NavigationPage(new RegisterUser()));
I found a solution, instead of using Navigation.PushAsync I used
Navigation.PushModalAsync(new NavigationPage(new RegisterPet()));
and also OnAppearing of RegisterPet page I added SetHasNavigationBar
protected override void OnAppearing()
{
InitializeSettings();
NavigationPage.SetHasNavigationBar(this, false);
base.OnAppearing();
}
Related
I have:
MainView.xaml
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="#fff"
...
>
<views:Page1 Title="Page1" IconImageSource="homeicon" BackgroundColor="#fff"/>
<views:Page2 Title="Page2" IconImageSource="order" BackgroundColor="#fff"/>
<views:Page3 Title="Page3" IconImageSource="ads" BackgroundColor="#fff"/>
<views:Page4 Title="Page4" IconImageSource="usericon" BackgroundColor="#fff"/>
</TabbedPage>
and i have 1 login page. After logging in, you will be redirected to Page4.
I use: App.Current.MainPage = new NavigationPage(new Page4())
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
App.Current.MainPage = new Page4();
}
However I don't show TabbedPage
How to show the list of Tabs below. Please help me with the solution. Thank you
Update
I try
On Log in => App.Current.MainPage = new MainView();
Log Out => App.Current.MainPage = new LoginPage();
It still doesn't work
Put your page inside a navigation page. That should help you fix it.
Update:
In MainView.xaml.cs put this
public MainView(int index)
{
InitializeComponent();
SetPage(index);
}
void SetPage(int index) { CurrentPage=Children[index]; }
after login, do this
App.Current.MainPage = new NavigationPage(new MainView(3))
When you change App.Current.MainPage, you change the MainPage of the app for anything you put there so that page is the only page that exists in the app. Try to set your tabbed page there and you will have the tabbed page as the 'MainPage'.
Now that your MainPage is the Tabbed Page, you can change the Page that is shown using the code below (inside the TabbedPage):
CurrentPage = Children[3]; // 0, 1, 2, 3
You will notice that you can change between any ContentPage attached to the TabbedPage
There is access to the MainPage everywhere now using (App.Current.MainPage as TabbedPage) so it's easy to change the shown page from other places
i want to navigate from a page(not main page) which is in a tabbed page to a page when clicking on a button. i tried this :
MainPage = new NavigationPage(new listofinterest());
MainPage = new TabbedPageMain()
{
BarBackgroundColor = Color.FromHex("#F8F8F8"),
};
////////
public partial class listofinterest : ContentPage
{
private async void Add(object sender, EventArgs e)
{
await Navigation.PushAsync(new NavigationPage(new MainPage()));
}
}
it didn't work i get this error
"PushAsync is not supported globally on Android, please use a NavigationPage.'"
i need help please.
The problem is your overriding the MainPage with the TabbedPageMain. Only set it once.
First set the MainPage in App.xaml.cs:
MainPage = new NavigationPage(new MyPage());
Then you can push other pages from MyPage like this:
await Navigation.PushAsync(new MyOtherPage());
it didn't work i get this error "PushAsync is not supported globally on Android, please use a NavigationPage.'" i need help please.
From your code and description, you want to navigate from one of Tabbedpages to other page in project. If yes, please add to a navigation stack is referred to as the root page of the application in App.xaml.cs.
public App()
{
InitializeComponent();
MainPage =new NavigationPage( new tabbedpage.TabbedPage1());
}
then Tabbedpage.xaml:
<TabbedPage
x:Class="FormsSample.tabbedpage.TabbedPage1"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:FormsSample.simplecontrol">
<!-- Pages can be added as references or inline -->
<TabbedPage.Children>
<local:Page1 />
<local:Page3 />
<local:Page4 />
</TabbedPage.Children>
Wanting to navigate Page1 from Tabbedpage to other page.
<ContentPage
x:Class="FormsSample.simplecontrol.Page1"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="page 1">
<ContentPage.Content>
<ScrollView>
<StackLayout x:Name="Contenttest">
<Button
x:Name="btn1"
Clicked="btn1_Clicked"
Text="navigate to another page" />
</StackLayout>
</ScrollView>
</ContentPage.Content>
private void btn1_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new simplecontrol.Page5());
}
About Navigation detailed info, please refer to
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical
I have a problem. I want to load a TabbedPage when I click on a button in a different page, so I created this code:
protected void imgAdd_Clicked(object sender, EventArgs args)
{
var tabbedPage = new TabbedPage();
tabbedPage.Children.Add(new Page1());
tabbedPage.Children.Add(new Page2());
App.Current.MainPage = tabbedPage;
}
But the result is as follows:
As you can see the Image leaves a trail of the image when you swipe between the pages.
However, when I load the Tabbed Page using the App.xaml.cs it loads correctly without the flickering, so it seems to only occur when I call the tabbed page from another page...
Any ideas?
I make the sample to test. You could check the sample TabbedPageDemo on my github.
https://github.com/WendyZang/Test.git
Create two pages.
Page1.xaml:
<StackLayout >
<Image Source="pig.jpg"></Image>
</StackLayout>
Page2.xaml:
<StackLayout>
<Image Source="world.jpg"></Image>
</StackLayout>
With the code you provided.
var tabbedPage = new TabbedPage();
tabbedPage.Children.Add(new Page1());
tabbedPage.Children.Add(new Page2());
App.Current.MainPage = tabbedPage;
Result:
Need more explanation about the issue,
The tabs in the Tabbedpage are dynamically created?
Suggestion: Use https://help.syncfusion.com/xamarin/tabbed-view/getting-started
it will save your time.
I've just started working on my very first Xamarin Forms app for Android, iOS and UWP and have looked through a lot of examples and code in order to get started.
The app is built using MVVM structure, as i guess most Xamarin.Forms apps are and I am currently facing two issues that I can't find any answer to.
These problems might be Xamarin.Forms 101 so I apologize if these are "stupid" questions.
App.xaml.cs -> App.MainPage = new NavigationPage(new MainPage())
In the App.xaml.cs file I have defined which page that should be set as the startup-page based on Device idiom.
Page startupPage = null;
if (Device.Idiom == TargetIdiom.Phone)
startupPage = new NavigationPage(new MainPage());
else
startupPage = new NavigationPage(new MainPageTablet());
MainPage = startupPage;
This works fine, but i face one issue with this.
OnAppearing() and OnDisappearing() are both called on startup
When the app starts, both OnAppearing() and OnDisappearing() are called inside MainPage.xaml.cs/MainPageTablet.xaml.cs file(s).
Is this a bug, or should this happen?
When removing "NavigationPage" from the declaration of startupPage only OnAppearing() is called on startup
Page startupPage = null;
if (Device.Idiom == TargetIdiom.Phone)
startupPage = new MainPage();
else
startupPage = new MainPageTablet();
MainPage = startupPage;
Now the startup works, like I feel it should with only calling OnAppearing() on startup.
This however now introduces some new "problem(?)". The ToolbarItem that i have inside MainPage.xaml/MainPageTablet.xaml disappears.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TestApp.Classes;assembly=TestApp"
x:Class="TestApp.Views.MainPageTablet">
<ContentPage.ToolbarItems>
<ToolbarItem Name="MenuItem1" Order="Secondary" Text="Log out" Command="{Binding LogOutCommand}" Icon="settingsImage.png" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
....
</ContentPage.Content>
</ContentPage>
Can a ToolbarItem only be used in a NavigationPage, or do I have to do more than just adding it to the in order to get it to work?
Any help or comments regarding this would be really helpful.
Thanks
If you are running your app on mobile, then on startup OnAppearing() of MainPage() should only be called.
If the page is setup as Navigation page, then only default navigation bar appears.
So when you add toolbar item it will be visible. But as you have not set main page as navigation page, navigation bar will not appear and so toolbar item is not visible.
When using MasterDetailPage in Xamarin.Forms it behaves as aspected in Android. Just like a normal Navigation Drawer. Please notice the correct behaviour of the slide-in mechanism and the correct placement of the hamburger-button. The Buttons in the menu work great as well.
The UWP App looks like this. Notice, there is no hamburger-button:
After klicking on a menu-button, the menu is gone without a possibility to get it back:
Here are some code excerpts:
App.xaml.cs
public partial class App : Application
{
public App()
{
MainPage = new NavigationPage(new MenuPage());
}
...
MenuPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WordDeck.MenuPage"
xmlns:local="clr-namespace:WordDeck;assembly=WordDeck"
Title="WordDeck."
MasterBehavior="Default">
<MasterDetailPage.Master>
<ContentPage Title="Menu">
<StackLayout Orientation="Vertical">
<Button Text="Neues Spiel"
Clicked="MainPage_Clicked"></Button>
<Button Text="Deck Verwaltung"
Clicked="DeckManager_Clicked"></Button>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<local:MainPage></local:MainPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
MenuPage.xaml.cs
public partial class MenuPage : MasterDetailPage
{
public MenuPage()
{
InitializeComponent();
}
private void MainPage_Clicked(object sender, EventArgs e)
{
Detail = new MainPage();
Title = "WordDeck.";
IsPresented = false;
}
private void DeckManager_Clicked(object sender, EventArgs e)
{
Detail = new DeckManagerPage();
Title = "Deck Verwaltung";
IsPresented = false;
}
}
MainPage and DeckManagerPage are nearly empty and of type ContentPage.
Why is there no menu Button on UWP?
It's because you're running the UWP app as a desktop app and not on the phone. If you run the app on a mobile phone or emulator you should see the menu as on Android.
If you want to use the hamburger behaviour when running as a desktop app set MasterBehavior = MasterBehavior.Popover on your MasterDetailPage
The main problem is the IsPresented on the desktop hides the drawer.
One way to handle this is not to hide on desktop or tablet.
For example...
// Called from each Clicked Event
private void SetPresentedVisability()
{
switch (Device.Idiom)
{
case TargetIdiom.Phone:
IsPresented = false;
break;
case TargetIdiom.Desktop:
case TargetIdiom.Tablet:
case TargetIdiom.Unsupported:
IsPresented = true;
break;
}
}
Alternately you could ignore any non phone IsPresented setting.
IsPresented = (Device.Idiom == TargetIdiom.Phone) ? false : true;