2

我正在尝试在 Xamarin Forms 中使用 Prism 创建一个应用程序。

Xamarin 表单版本:2.3.3.175

棱镜版本:6.2.0

汉堡菜单适用于 Android,但是当我在 UWP 运行它时,它不会显示图标,而且当我浏览菜单时,菜单完全消失,我也不会让该方法返回其他页面。换句话说,我需要关闭并重新启动应用程序。

这是我到目前为止所尝试的。

  1. 创建棱镜项目后,我添加了一个 MasterDetailPage:

    <MasterDetailPage.Master>
        <ContentPage Title="Default">
            <StackLayout>
                <Button Text="Billing" Command="{Binding Path=NavigationCommand}" CommandParameter="MyNavigationPage/BillingPage"/>
                <Button Text="Your Order" Command="{Binding Path=NavigationCommand}" CommandParameter="MyNavigationPage/PlaceOrderPage"/>
                <Button Text="Settings" Command="{Binding Path=NavigationCommand}" CommandParameter="MyNavigationPage/SettingsPage"/>
                <Button Text="Settings"/>
            </StackLayout>
        </ContentPage>
    </MasterDetailPage.Master>
    

MasterDetailPage ViewModel

public class MDPageViewModel : BindableBase
    {
        private INavigationService _navigationService;


        public DelegateCommand<string> NavigationCommand => new DelegateCommand<string>(Navigation);



        public MDPageViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;

        }

        private void Navigation(string page)
        {
            _navigationService.NavigateAsync(page);
        }
    }
  1. 之后,我创建了一个导航页面以及相应的页面和视图模型。这是 App.Xaml.cs 文件:

    公共部分类应用程序:PrismApplication {公共应用程序(IPlatformInitializer初始化程序= null):基础(初始化程序){}

        protected override void OnInitialized()
        {
            InitializeComponent();
    
            NavigationService.NavigateAsync("MDPage/MyNavigationPage/ItemsPage");
        }
    
        protected override void RegisterTypes()
        {
            Container.RegisterTypeForNavigation<MDPage>();
            Container.RegisterTypeForNavigation<BillingPage>();
            Container.RegisterTypeForNavigation<PlaceOrderPage>();
            Container.RegisterTypeForNavigation<SettingsPage>();
            Container.RegisterTypeForNavigation<MyNavigationPage>();
        }
    }
    
  2. 所以当我在 UWP 中运行应用程序时,它会像这样加载 在此处输入图像描述

但是当我点击菜单中的链接时,菜单会消失,看起来像这样。

在此处输入图像描述

我做错了什么,我该如何解决?

我在 github 中创建了一个项目,因此您可以轻松查看错误。

https://github.com/codemasterblackperl/Hamburger_Menu_Prism_Forms_Repo

4

3 回答 3

2

这是最新版本的 Xamarin 中的一个错误。它在使用 2.3.1.114 时有效。自从我遇到这个问题以来,我已经在这里发布了这个错误。

于 2017-01-08T04:09:21.907 回答
0

这只会部分回答您的问题。尽管 Prism.Forms 文档中记录了该图标,但我也无法看到该图标。要获取图标,请转到 UWP 项目中的 App.Xaml 并在其间添加以下数据模板<Application.Resources>...</Application.Resources>

<DataTemplate x:Key="ItemTemplate">
    <uwp:ItemControl HorizontalContentAlignment="Stretch"
                     VerticalContentAlignment="Stretch" />
</DataTemplate>

在顶部定义 uwp 前缀,例如 xmlns:uwp="using:Xamarin.Forms.Platform"

您的 App.Xaml 应如下所示:

<Application x:Class="MyApp.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:uwp="using:Xamarin.Forms.Platform">
<Application.Resources>
    <DataTemplate x:Key="ItemTemplate">
        <uwp:ItemControl HorizontalContentAlignment="Stretch"
                         VerticalContentAlignment="Stretch" />
    </DataTemplate>
</Application.Resources>

完成后,它将显示图标。但是,这将告诉您,一旦您单击主文件中的项目,菜单就会折叠。我无法解决这个问题。

于 2016-12-19T07:20:50.067 回答
0

只需在 MasterDetail 代码隐藏中使用 IMasterDetailPageOptions 接口:

public partial class ShellView : MasterDetailPage, IMasterDetailPageOptions
{
    public ShellView()
    {
        InitializeComponent();
    }

    public bool IsPresentedAfterNavigation
    {
        get { return Device.Idiom != TargetIdiom.Phone; }
    }
}
于 2017-01-13T14:40:36.690 回答