汉堡菜单没有在iOS上显示。 Prism问题,Xamarin问题或我的问题

时间:2017-08-03 08:42:22

标签: xamarin xamarin.ios prism hamburger-menu

我正在尝试使用汉堡菜单实现masterDetail应用程序。 它可以在Android上运行但在iOS上崩溃时会出现“FileNotFoundException”并显示默认值而不是图标。

我在iOS上添加了一个图标。资源项目但仍未显示,主页面和导航页面都有图标。

我做错了吗? 任何解决方法? 非常感谢

的App.xaml

    public partial class App : PrismApplication
    {
        public App(IPlatformInitializer initializer = null) : base(initializer) { }

        protected override void OnInitialized()
        {
            try
            {
                InitializeComponent();

                NavigationService.NavigateAsync("MainMasterDetail/MyNavigationPage/MainPage",animated:false);
            }
            catch (Exception e)
            {
               Debug.WriteLine(e.ToString());
            }           
        }

        protected override void RegisterTypes()
        {
            Container.RegisterTypeForNavigation<MainMasterDetail,MainMasterDetailViewModel>();
            Container.RegisterTypeForNavigation<MyNavigationPage,MyNavigationPageViewModel>();
            Container.RegisterTypeForNavigation<MainPage>();
            Container.RegisterTypeForNavigation<ViewA,ViewAViewModel>();
            Container.RegisterTypeForNavigation<ViewB,ViewBViewModel>();

        }
    }

MainMasterDetails.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"
                          xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
                          prism:ViewModelLocator.AutowireViewModel="True"
                          x:Class="HelloBurgerMenu.Views.MainMasterDetail"
                          Title="MainMasterDetail" Icon="humburger.png">
            <MasterDetailPage.Master>
                <ContentPage Title="Default">
                    <StackLayout>
                        <Button Text="MainPage" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/MainPage" />
                        <Button Text="ViewA" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewA" />
                        <Button Text="ViewB" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewB" />
                    </StackLayout>
                </ContentPage>
            </MasterDetailPage.Master>

        </MasterDetailPage>


MyNavigationPage

    <?xml version="1.0" encoding="utf-8" ?>
    <NavigationPage 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="HelloBurgerMenu.Views.MyNavigationPage"
                    Icon="humburger.png">

    </NavigationPage>

2 个答案:

答案 0 :(得分:1)

尝试在MasterPage中指定Icon而不是MasterDetail

 public MasterPage()
 {
    InitializeComponent();
    if (Device.RuntimePlatform == Device.iOS)
    {
       Icon = "menu.png";
    } 
 }

答案 1 :(得分:0)

您的NavigationPage中不能包含内容。删除NavigationPage中的所有XAML。

请看这个示例:https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage