예제 #1
0
 /// <summary>
 /// 在此页将要在 Frame 中显示时进行调用。
 /// </summary>
 /// <param name="e">描述如何访问此页的事件数据。
 /// 此参数通常用于配置页。</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if(e.NavigationMode== NavigationMode.Back)
     {
         _HomeViewModel = Helper.Declares.CatachHomePageData;
     }
 }
예제 #2
0
 public HomePage()
 {
     _HomeViewModel = new ViewModel.HomeViewModel();
     this.DataContext = _HomeViewModel;
     this.InitializeComponent();
 }
예제 #3
0
        public Home()
        {
            InitializeComponent();

            BindingContext = new ViewModel.HomeViewModel();
        }
예제 #4
0
 public Home()
 {
     this.InitializeComponent();
     viewmodel        = new ViewModel.HomeViewModel();
     this.DataContext = viewmodel;
 }
예제 #5
0
        void LoadMenuBasedSampleApp()
        {
            var nav = new NavigationPage(new ContentPage
            {
                Title   = "Xamarin.Essentials",
                Content = new Label
                {
                    Text = "Select a sample from the \"Samples\" menu...",
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center,
                },
            });

            LoadApplication(new App {
                MainPage = nav
            });

            // load the menu
            var mainMenu    = NSApplication.SharedApplication.MainMenu;
            var samplesMenu = mainMenu.ItemWithTitle("Samples");

            // deselect the samples when we return to the home page
            nav.Popped += (s, e) =>
            {
                if (nav.StackDepth == 1)
                {
                    SelectSampleMenuItem(null);
                }
            };

            // add the samples to the main menu
            var home       = new ViewModel.HomeViewModel();
            var allSamples = home.FilteredItems.ToList();

            for (var i = 0; i < allSamples.Count; i++)
            {
                var sample   = allSamples[i];
                var menuItem = new NSMenuItem(sample.Name, OnSampleSelected);
                menuItem.Tag     = i;
                menuItem.ToolTip = sample.Description;
                samplesMenu.Submenu.AddItem(menuItem);
            }

            async void OnSampleSelected(object sender, EventArgs e)
            {
                if (sender is NSMenuItem menuItem)
                {
                    SelectSampleMenuItem(menuItem);

                    var sample = allSamples[(int)menuItem.Tag];
                    await nav.PushAsync((Page)Activator.CreateInstance(sample.PageType));
                }
            }

            void SelectSampleMenuItem(NSMenuItem menuItem)
            {
                // deselect previous
                foreach (var mi in samplesMenu.Submenu.Items)
                {
                    mi.State = NSCellStateValue.Off;
                }

                // select this one
                if (menuItem != null)
                {
                    menuItem.State = NSCellStateValue.On;
                }
            }
        }