【问题标题】:Hamburger menu not showing on iOS . Prism issue, Xamarin issue or my issue汉堡菜单未在 iOS 上显示。棱镜问题,Xamarin 问题或我的问题
【发布时间】:2017-08-03 08:42:22
【问题描述】:

我正在尝试使用汉堡菜单实现 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>

【问题讨论】:

    标签: xamarin xamarin.ios prism hamburger-menu


    【解决方案1】:

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

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

    【讨论】:

    • "从 4.0.0 开始,图标已过时。请改用 IconImageSource。"
    【解决方案2】:

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

    看看这个样本:https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage

    【讨论】:

    • 您好,谢谢,但这是一个复制和粘贴错误。这是空的。通过在内容页面上设置图标,它甚至认为它会因“filenotfound”而崩溃,但图标在那里。向前导航时是否应该显示带有标题而不是 Hamburger.png 的后退箭头?
    • 如果你去掉汉堡包图标,它会起作用吗?如果是这样,您就知道是什么问题了..
    • 你不把汉堡图标加到导航页上,你加到master上。
    猜你喜欢
    • 1970-01-01
    • 2021-09-05
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    相关资源
    最近更新 更多