如何使用Prism导航正确设置标签页?

时间:2016-04-15 08:44:07

标签: mvvm prism xamarin.forms

我需要标签页作为主页,子成员作为导航页面。 这是使用List制作iOS应用程序然后从行导航到详细信息页面的经典方法。

我在项目和导航工作中设置了Xamarin.Prism导航,但我无法使用后退按钮或后退箭头设置导航栏。

我的主页XAML:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
        prism:ViewModelLocator.AutowireViewModel="True"
        xmlns:views="clr-namespace:TestPortable.Views;assembly=TestPortable"
        x:Class="TestPortable.Views.MainPage">
  <TabbedPage.Children>

    <NavigationPage Title="Users" BarBackgroundColor="Maroon" BarTextColor="White">
      <x:Arguments>
        <views:Users />
      </x:Arguments>
    </NavigationPage>

    <NavigationPage Title="Likes" BarBackgroundColor="Maroon" BarTextColor="White">
      <x:Arguments>
        <views:Likes />
      </x:Arguments>
    </NavigationPage>

  </TabbedPage.Children>
</TabbedPage>  

我的详细信息XAML页面(详情页面也有&#34;保存&#34;按钮):

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
         prism:ViewModelLocator.AutowireViewModel="True"
         x:Class="TestPortable.Views.UserDetail"
         Title="Detail">

  <ContentPage.ToolbarItems>
      <ToolbarItem Text="Save" Command="{Binding SaveClick}"/>
  </ContentPage.ToolbarItems>

  <StackLayout VerticalOptions="Center">
    <Label Text="{Binding SelectedUser.Email}" TextColor="Black"/>
    <Image Source="{Binding SelectedImage.Source}"
       HeightRequest="200"
       WidthRequest="200"
       Aspect="AspectFill"
       BackgroundColor="Aqua"/>
  </StackLayout>

</ContentPage>

UserDetail.xaml.cs逻辑在这里:

[NavigationPageProvider(typeof(UserDetailNavigationPageProvider))]
public partial class UserDetail : ContentPage
{
    public UserDetail()
    {
        InitializeComponent();
    }

}

public class UserDetailNavigationPageProvider : INavigationPageProvider
{
    public Page CreatePageForNavigation(Page sourcePage, Page targetPage)
    {
        NavigationPage.SetHasNavigationBar(targetPage, true);
        NavigationPage.SetBackButtonTitle(targetPage, "Back");
        NavigationPage.SetHasBackButton(targetPage, true);

        var newPage = new NavigationPage(targetPage);
        newPage.BarBackgroundColor = Color.Maroon;
        newPage.BarTextColor = Color.White;

        return newPage;
    }
}

当我从列表视图导航到详细信息页面时,我正在获取带导航栏的详细信息页面,但没有&#34;返回&#34;按钮或后退箭头。 有没有人解决这种情况?

0 个答案:

没有答案