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