英文:
Page Title Not Shown On Content Page
问题
I set visibility of this page's navigation bar and my title was gone like that.
But there is a blue bar I can navigate back. I'm new at Xamarin Forms. I don't know its name, but it works now. I want to show my page's title on that blue bar, not the Navigation bar. My page title must be shown on that empty space in the picture. How can I do that?
Xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
xmlns:local="clr-namespace:İdaServis.ViewModels"
xmlns:renderers="clr-namespace:İdaServis.CustomRenderer"
x:Class="İdaServis.View.PageName"
Title="{Binding Title}"
x:Name="Page"
BackgroundColor="White">
</ContentPage>
CS:
public PageName()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
英文:
I set visibiliy of this page's navigation bar and my title was gone like that.
But there is a bluebar i can navigate back. I'm new at xamarin forms. I dont know its name but it works now. I want to show my page's title on that blue bar, not the Navigation bar. My page title must be shown on that empty space on the picture. How can i do that ?
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
xmlns:local="clr-namespace:İdaServis.ViewModels"
xmlns:renderers="clr-namespace:İdaServis.CustomRenderer"
x:Class="İdaServis.View.PageName"
Title="{Binding Title}"
x:Name="Page"
BackgroundColor="White">
</ContentPage>
CS:
public PageName()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
答案1
得分: 1
Here is the translated content:
如果您想在蓝色条上显示页面标题而不是导航栏,请将NavigationPage.SetHasNavigationBar
的第二个参数设置为true
:
public PageName()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, true);
}
然后,您可以通过为页面添加代码Title="My Page"
来设置页面标题,就像下面这样:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="My Page"
x:Class="MVVMApp.SecondPage">
</ContentPage>
当然,您还可以使用TitleView
来自定义标题栏,例如:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="My Page"
x:Class="MVVMApp.SecondPage">
<NavigationPage.TitleView>
<Label Text="自定义标题栏-----"/>
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout>
<Label Text="欢迎访问第二页"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
英文:
> I want to show my page's title on that blue bar, not the Navigation
> bar.
If you want show your page's title on that blue bar, please set the second parameter of NavigationPage.SetHasNavigationBar
to true
:
public PageName()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, true);
}
Then you can set your page's title by adding code Title="My Page"
for your Page. Just as follows:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="My Page"
x:Class="MVVMApp.SecondPage">
</ContentPage>
Of cource, you can also custom this with TitleView
.
For example:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="My Page"
x:Class="MVVMApp.SecondPage">
<NavigationPage.TitleView>
<Label Text="custom TitleView----->"/>
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to secoend page"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
答案2
得分: 1
为了重现您的问题,我在官方示例FlyoutSample中添加了一个LoginPage
。
类的顺序是:App.cs
--> Login
--> MainPage(FlyoutPage)
。
步骤如下:
- 在
App.cs
中,将MainPage = new FlyoutPageNavigation.MainPage ();
替换为MainPage = new NavigationPage(new Login());
public class App : Application
{
public App ()
{
//MainPage = new FlyoutPageNavigation.MainPage ();
MainPage = new NavigationPage(new Login());
}
}
- 在
Login.xaml.cs
页面上,添加一个按钮以导航到MainPage(FlyoutPage)
。
public partial class Login : ContentPage
{
public Login()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new MainPage());// 这将添加另一个导航栏
// 使用Navigation.PushModalAsync不会添加导航栏
//Navigation.PushModalAsync(new MainPage());
}
}
注意:
在Button_Clicked
方法中,如果您使用以下代码,将在屏幕顶部添加一个导航栏。如果使用FlyoutPage
,则无需添加此导航栏。
Navigation.PushAsync(new MainPage());
因此,请尝试改用Navigation.PushModalAsync
:
Navigation.PushModalAsync(new MainPage());
英文:
To reproduce your problem, I added a LoginPage
to offcial sample FlyoutSample.
The class order is: App.cs
--> Login
--> MainPage(FlyoutPage)
.
The steps are as follows:
1.In App.cs
,replace MainPage = new FlyoutPageNavigation.MainPage ();
with MainPage = new NavigationPage(new Login());
public class App : Application
{
public App ()
{
//MainPage = new FlyoutPageNavigation.MainPage ();
MainPage = new NavigationPage(new Login());
}
}
2.On Page Login.xaml.cs
,add a Button to navigate to MainPage(FlyoutPage)
public partial class Login : ContentPage
{
public Login()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new MainPage());// this will add another navigate bar
// Navigation.PushModalAsync will not add the navigate bar
//Navigation.PushModalAsync(new MainPage());
}
}
Note:
In method Button_Clicked
,if you used the following code, a navigate bar will be added to the top of the screen. If you used FlyoutPage
,there is no need to add this navigate bar.
Navigation.PushAsync(new MainPage());
So, try to use Navigation.PushModalAsync
instead:
Navigation.PushModalAsync(new MainPage());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论