private void NavigateToPage(GoToPage message) { try { Frame rootFrame = Window.Current.Content as Frame; switch (message.Name) { case "Login": SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; rootFrame.Navigate(typeof(Login)); break; case "MainView": rootFrame.Navigate(typeof(MainView), true); break; case "Register": rootFrame.Navigate(typeof(Register), true); break; default: rootFrame.Navigate(typeof(Login)); break; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private void OnConnected(MPC sender) { Debug.WriteLine("OnConnected@ConnectViewModel"); IsBusy = false; ConnectionStatus = "Connected! Saving connection info..."; Profile pro = new Profile(); pro.Name = Host + ":" + _port.ToString(); pro.Host = Host; pro.Port = _port; pro.Password = Password; pro.IsDefault = true; _con.Profiles.Add(pro); _con.SaveProfile(); ConnectionStatus = "..."; Device.BeginInvokeOnMainThread( () => { GoToPage?.Invoke(this, "HomePage"); }); }
public MainPageViewModel(INavigationService navigationService) { GoToPage.Subscribe(async p => { await navigationService.NavigateAsync(p + "Page"); }); GoToTest.Subscribe(async p => { await navigationService.NavigateAsync(p); }); }
// // Method to connection to other pages. // private object GoToPage(string pageNum) { var msg = new GoToPage() { PageName = pageNum }; Messenger.Default.Send <GoToPage>(msg); return(null); }
private void OnConnected(MPC sender) { Debug.WriteLine("OnConnected@SettingViewModel"); IsBusy = false; SettingProfileEditMessage = "Connected!"; Device.BeginInvokeOnMainThread( () => { GoToPage?.Invoke(this, "HomePage"); }); SettingProfileEditMessage = ""; }
// // The page navigation login has to be here, because the "frmMain" is the Frame // control that contains all other views. // private object ReceiveMessage(GoToPage action) { StringBuilder sb = new StringBuilder("/Views/"); sb.Append(action.PageName); sb.Append(".xaml"); try { this.frmMain.NavigationService.Navigate(new System.Uri(sb.ToString(), System.UriKind.Relative)); } catch (Exception) { MessageBox.Show("Can not find " + action.PageName + " page."); } return(null); }
/// <summary> /// 初始化控件 /// </summary> /// <param name="GP">代理</param> public void InitControl(GoToPage GP) { _GoToPage = GP; }
private void ConnectPage(IDomain domain, string goToPageName) { foreach (IPage Item in domain.Pages) { if (Item.Name == goToPageName) { GoToPage = Item; break; } } if (GoToPage == null && goToPageName == Page.CurrentPage.Name) { GoToPage = Page.CurrentPage; } else if (GoToPage == null && goToPageName == Page.PreviousPage.Name) { GoToPage = Page.PreviousPage; } else if (GoToPage != null) { GoToPage.SetIsReachable(); } else { string[] Splitted = goToPageName.Split(':'); string SplittedPrefix = Splitted.Length > 0 && Splitted[0].Length > 0 ? Splitted[0] : ""; string SplittedSuffix = Splitted.Length > 1 && Splitted[1].Length > 0 ? Splitted[1].Substring(Splitted[1].Length - 1) : ""; string AnyPagePrefix = Page.AnyPage.Name.Substring(0, Page.AnyPage.Name.Length - 1); string AnyPageSuffix = Page.AnyPage.Name.Substring(Page.AnyPage.Name.Length - 1); if (SplittedPrefix == AnyPagePrefix && SplittedSuffix == AnyPageSuffix) { GoToPage = Page.AnyPage; string[] AlternateNames = Splitted[1].Substring(0, Splitted[1].Length - 1).Split(';'); foreach (string AlternateName in AlternateNames) { string TrimmedAlternate = AlternateName.Trim(); IPage Alternate = null; foreach (IPage Item in domain.Pages) { if (Item.Name == TrimmedAlternate) { Alternate = Item; break; } } if (Alternate != null) { if (AlternatePages.Contains(Alternate)) { throw new ParsingException(222, NavigationSource.Source, $"Custom page destination '{TrimmedAlternate}' is repeated."); } Alternate.SetIsReachable(); AlternatePages.Add(Alternate); } else if (AlternateName == Page.CurrentPage.Name) { if (!AlternatePages.Contains(Page.CurrentPage)) { AlternatePages.Add(Page.CurrentPage); } } else if (AlternateName == Page.PreviousPage.Name) { if (!AlternatePages.Contains(Page.PreviousPage)) { AlternatePages.Add(Page.PreviousPage); } } else { throw new ParsingException(176, NavigationSource.Source, $"Unknown page name '{TrimmedAlternate}'."); } } if (AlternatePages.Count == 0) { throw new ParsingException(223, NavigationSource.Source, "A custom page must declare at least one destination page."); } } } if (BeforeObjectEvent != null) { BeforeObjectEvent.SetIsProvidingCustomPageName(NavigationSource, GoToPage == Page.AnyPage); } if (GoToPage == null) { throw new ParsingException(176, NavigationSource.Source, $"Unknown page name '{goToPageName}'."); } if (GoToPage == Page.AnyPage && (BeforeObject == null || BeforeObjectEvent == null)) { throw new ParsingException(177, NavigationSource.Source, "A custom page must be set with a 'before' event."); } }