代码之家  ›  专栏  ›  技术社区  ›  JL1

窗体默认的MaSTeLoad项目应用程序。

  •  0
  • JL1  · 技术社区  · 6 年前

    我真的想通过XAMARIA.Spple应用程序来工作。我发现它很难,因为模板中的模板似乎不起作用。

    基本上在菜单上我试图导航到浏览或关于页面。 然而 MainPage RootPage { get => Application.Current.MainPage as MainPage; } 正在返回空值。

    我没有对这个模板做任何更改,但我确实理解c所以我大致理解这个问题,但我不知道为什么它返回null,当然是从起始模板返回的。

    MenuPage.xaml.xs

    using ProspectGator.Models;
    using System;
    using System.Collections.Generic;
    
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;
    
    namespace ProspectGator.Views
    {
        [XamlCompilation(XamlCompilationOptions.Compile)]
        public partial class MenuPage : ContentPage
        {
            MainPage RootPage { get => Application.Current.MainPage as MainPage; }
            List<HomeMenuItem> menuItems;
            public MenuPage()
            {
                InitializeComponent();
    
            menuItems = new List<HomeMenuItem>
            {
                new HomeMenuItem {Id = MenuItemType.Browse, Title="Browse" },
                new HomeMenuItem {Id = MenuItemType.About, Title="About" }
            };
    
            ListViewMenu.ItemsSource = menuItems;
    
            ListViewMenu.SelectedItem = menuItems[0];
            ListViewMenu.ItemSelected += async (sender, e) =>
            {
                if (e.SelectedItem == null)
                    return;
    
                var id = (int)((HomeMenuItem)e.SelectedItem).Id;
                await RootPage.NavigateFromMenu(id);
            };
        }
    }
    }
    

    App.xaml.cs

    using System;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;
    using ProspectGator.Views;
    
    [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
    namespace ProspectGator
    {
        public partial class App : Application
        {
    
            public App()
            {
                InitializeComponent();
                MainPage = new NavigationPage( new  MainPage());
    
            }
    
            protected override void OnStart()
            {
                // Handle when your app starts
            }
    
            protected override void OnSleep()
            {
                // Handle when your app sleeps
            }
    
            protected override void OnResume()
            {
                // Handle when your app resumes
            }
        }
    }
    

    通常,我希望设置或已经设置此属性,但我不确定。我确实有 MainPage.xaml .

    0 回复  |  直到 6 年前