在我的xamarin.forms项目中,Page1是一个在navigatonbar上具有母版页标题的详细信息页面。当我使用PushAsync从page1 viewmodel导航到page3时,page3有主页面标题和导航栏后退按钮。当我从page1 viewmodel导航到page2时,page2只有navbackbutton,没有主标题。当从page2 viewmodel导航到page3,page3也没有主标题,只有navbackbutton。我在Android上没有这个问题。如何在iOS上从page1 viewmodel导航到page3时隐藏主页面标题?
page1 cs:vm方法调用移动到page3
private async void Cart_Tapped(object sender, EventArgs e)
{
await img_cart.FadeTo(0.3, 500);
await img_cart.FadeTo(1, 500);
var vm = BindingContext as Main_page_vm;
vm?.Save_cart();
}
从page1 viewmodel导航到page3:详细信息页面到有问题的内容页面
internal async void Save_cart()
{
if(Number.Equals(0))
{
App.Current.Properties["cartitems"] = purchaselist;
DependencyService.Get<IToast>().LongAlert("Empty cart !");
}
else
{
App.Current.Properties["cartitems"] = purchaselist;
List<tb_login> Login_list = App.Database.Get_user_id();
if (!Login_list.Count.Equals(0))
{
foreach (tb_login tb_Login in Login_list)
{
App.Current.Properties["user_id"] = tb_Login.user_id;
App.Current.Properties["username"] = tb_Login.user_name;
}
await Navigation.PushAsync(new Address_page2()); //to page3,now showing master
}
else
{
await Navigation.PushAsync(new LoginPage());
}
}
}
第1页到第2页:详细信息页面到内容页面,没有问题
private async void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as HomePageMenuItem;
if (item == null)
return;
if (item.Id == 0)
{
// Detail = new NavigationPage(new HomelyPage());
await Navigation.PushAsync(new HomelyPage());//to page2 has no master issues
}
IsPresented = false;
MasterPage.ListView.SelectedItem = null;
}
Page2 viewmodel to page3:内容页面到内容页面,没有问题
public async void Save_cart()
{
if (Number.Equals(0))
{
App.Current.Properties["cartitems"] = purchaselist;
DependencyService.Get<IToast>().LongAlert("Empty cart !");
}
else
{
App.Current.Properties["cartitems"] = purchaselist;
List<tb_login> Login_list = App.Database.Get_user_id();
if (!Login_list.Count.Equals(0))
{
foreach (tb_login tb_Login in Login_list)
{
App.Current.Properties["user_id"] = tb_Login.user_id;
App.Current.Properties["username"] = tb_Login.user_name;
}
await Navigation.PushAsync(new Address_page2()); //to page3,also not showing master
}
else
{
await Navigation.PushAsync(new LoginPage());
}
}
}
page1 xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="OnRestaur.Views.Main_Page"
BackgroundColor="#f2f2f2"
NavigationPage.HasBackButton="False">
<NavigationPage.TitleView>
<StackLayout HorizontalOptions="EndAndExpand">
<Grid HorizontalOptions="EndAndExpand">
<Label Text="{Binding Number, Mode=TwoWay}" FontAttributes="Bold" HorizontalOptions="EndAndExpand" FontSize="Small" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" Margin="0,0,32,10" Style="{StaticResource Label_font}" TextColor="White">
</Label>
<Image Source="shoppingcart_white.png" x:Name="img_cart" HorizontalOptions="EndAndExpand" WidthRequest="60" HeightRequest="50" Margin="0,0,10,0">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="Cart_Tapped" />
</Image.GestureRecognizers>
</Image>
</Grid>
</StackLayout>
</NavigationPage.TitleView>
第3页:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="OnRestaur.Views.Address_page2"
NavigationPage.HasBackButton="False"
Title=" ">
<NavigationPage.TitleView>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal" Margin="0" Spacing="0" Padding="0">
<Image Source="back_arrow.png" x:Name="img_cart" HorizontalOptions="StartAndExpand" WidthRequest="30" HeightRequest="30" Margin="0,0,0,0">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="Back_arrow_Tapped" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</NavigationPage.TitleView>
第2页xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Home"
x:Class="OnRestaur.Views.HomelyPage"
xmlns:local="OnRestaur.Views;assembly=ContentView"
xmlns:custom="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
NavigationPage.HasBackButton="False">
<NavigationPage.TitleView>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="back_arrow.png" HorizontalOptions="StartAndExpand" WidthRequest="30" HeightRequest="30" Margin="0,0,0,0">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="Back_arrow_Tapped" />
</Image.GestureRecognizers>
</Image>
<Grid HorizontalOptions="EndAndExpand">
<Image Source="loc.png" x:Name="img_cart" HorizontalOptions="EndAndExpand" WidthRequest="20" HeightRequest="20" Margin="0,0,30,0">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="Loc_Tapped" />
</Image.GestureRecognizers>
</Image>
</Grid>
</StackLayout>
</NavigationPage.TitleView>
将导航更改为类似下面的内容,它应该可以解决您的问题:
Application.Current.MainPage.Navigation.PushAsync(new Address_page2());