private void NavMenuListView_ItemClick(object sender, ItemClickEventArgs e) { // 遍历,将选中Rectangle隐藏 foreach (var np in navMenuPrimaryItem) { np.Color = new SolidColorBrush(Colors.White); np.Selected = Visibility.Collapsed; } foreach (var ns in navMenuSecondaryItem) { ns.Color = new SolidColorBrush(Colors.White); ns.Selected = Visibility.Collapsed; } NavMenuItem item = e.ClickedItem as NavMenuItem; // Rectangle显示并导航 item.Selected = Visibility.Visible; item.Color = new SolidColorBrush(brush); if (item.DestPage != null) { RootFrame.Navigate(item.DestPage); } if (Window.Current.Bounds.Width < 1008) { RootSplitView.IsPaneOpen = false; } }
private void Login_SignInCompleted(object sender, Microsoft.Toolkit.Uwp.UI.Controls.Graph.SignInEventArgs e) { // Set the auth state SetAuthState(true); // Reload the home page RootFrame.Navigate(typeof(HomePage)); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="args">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs args) { Task launchTask = null; await PrepareWindow(args); if (RootFrame.Content == null) { launchTask = MainVm.CurrentConnection.OnLaunch(); //else { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!RootFrame.Navigate(typeof(HubPage))) { throw new Exception("Failed to create initial page"); } } } // Ensure the current window is active Window.Current.Activate(); await RegisterBackgroundTask(); if (launchTask != null) { await launchTask; } }
private void ForwardButton_Click(object sender, RoutedEventArgs e) { if (RootFrame.CanGoForward) { RootFrame.GoForward(); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { RootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (RootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page RootFrame = new Frame(); RootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = RootFrame; } if (RootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter RootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }
public static bool GoBack() { try { var op = HistoryOperationsBeyondFrame.Pop(); if (!op.Invoke()) { throw new InvalidOperationException(); } else { return(true); } } catch (InvalidOperationException) { if (RootFrame.CanGoBack) { RootFrame.GoBack(); return(true); } else { return(false); } } }
/// <summary> /// Use this method to restore session state and navigation history. This method should only be called if Initialize() has already been executed./> /// </summary> /// <returns> /// True if app state was successfully restored. /// </returns> public static async Task <bool> TryRestoreState() { try { StorageFile navFile = await _folder.GetFileAsync(NAV_FILE_NAME); StorageFile stateFile = await _folder.GetFileAsync(STATE_FILE_NAME); PageStates = await StorageHelper.TryReadAsync <List <Dictionary <string, object> > >(stateFile, _standardKnownTypes); int topIndex = PageStates.Count - 1; _pageState = PageStates[topIndex]; PageStates.RemoveAt(topIndex); string navHistory = await StorageHelper.TryReadAsync(navFile); RootFrame.SetNavigationState(navHistory); return(true); } catch { return(false); } }
public MainPage() { this.InitializeComponent(); // Load OAuth settings var oauthSettings = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView("OAuth"); var appId = oauthSettings.GetString("AppId"); var scopes = oauthSettings.GetString("Scopes"); if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(scopes)) { Notification.Show("Could not load OAuth Settings from resource file."); } else { // Configure MSAL provider MsalProvider.ClientId = appId; MsalProvider.Scopes = new ScopeSet(scopes.Split(' ')); // Handle auth state change ProviderManager.Instance.ProviderUpdated += ProviderUpdated; // Navigate to HomePage.xaml RootFrame.Navigate(typeof(HomePage)); } }
private void ProviderUpdated(object sender, ProviderUpdatedEventArgs e) { var globalProvider = ProviderManager.Instance.GlobalProvider; SetAuthState(globalProvider != null && globalProvider.State == ProviderState.SignedIn); RootFrame.Navigate(typeof(HomePage)); }
private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args) { var invokedItem = args.InvokedItem as string; switch (invokedItem.ToLower()) { case "messages": RootFrame.Navigate(typeof(MessagesPage)); break; case "contacts": RootFrame.Navigate(typeof(ContactsPage)); break; case "events": RootFrame.Navigate(typeof(EventsPage)); break; case "driveitems": RootFrame.Navigate(typeof(DriveItemsPage)); break; case "home": default: RootFrame.Navigate(typeof(HomePage)); break; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); RootFrame.Navigate(typeof(NewsPage)); InitializeNavigationItems(); RegisterEvents(); }
/// <summary>Creates the application's root frame and loads the first page if needed. /// Also calls <see cref="OnInitializedAsync"/> when the application is instantiated the first time. </summary> /// <param name="executionState">The application execution state. </param> /// <returns>The task. </returns> protected async Task InitializeFrameAsync(ApplicationExecutionState executionState) { if (Window.Current.Content == null) { WindowContent = CreateWindowContentElement(); RootFrame = GetFrame(WindowContent); MtSuspensionManager.RegisterFrame(RootFrame, "AppFrame"); if (executionState == ApplicationExecutionState.Terminated) { await RestoreStateAsync(); } var task = OnInitializedAsync(RootFrame, executionState); if (task != null) { await task; } Window.Current.Content = WindowContent; } else { RootFrame = GetFrame(Window.Current.Content); } if (RootFrame.Content == null) { RootFrame.Initialize(StartPageType); } Window.Current.Activate(); }
protected override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args) { if (Debugger.IsAttached) { DebugSettings.EnableFrameRateCounter = false; DebugSettings.IsTextPerformanceVisualizationEnabled = false; DebugSettings.IsOverdrawHeatMapEnabled = false; Observable .FromEventPattern <Windows.UI.Xaml.BindingFailedEventHandler, Windows.UI.Xaml.BindingFailedEventArgs>( x => DebugSettings.BindingFailed += x, x => DebugSettings.BindingFailed -= x) .Select(x => x.EventArgs) .Subscribe( failedBinding => { Debugger.Break(); } ); } await Router.Navigate.Execute(new HomeViewModel()).ToTask(); RootFrame.Navigate(typeof(Shell)); }
private void PrevButton_Click(object sender, RoutedEventArgs e) { if (RootFrame.CanGoBack) { RootFrame.GoBack(); } }
public void Showing() { if (RootFrame.CurrentContentObject != ViewModel) { RootFrame.NavigateTo(ViewModel); } }
private void SecondListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { var listBoxItem = (ListBoxItem)((ListBox)sender).SelectedItem; if (listBoxItem != null) { var listBoxItemName = listBoxItem.Name; switch (listBoxItemName) { case "IDEBoxItem": // IDEPage RootFrame.Navigate(Global.PageManager[0, 0]); break; case "RuntimeBoxItem": // RuntimePage RootFrame.Navigate(Global.PageManager[0, 1]); break; default: break; } } } catch { // ignored } }
/// <summary> /// Starts authorization process. Opens and requests for access if VK App is installed. /// Otherwise SDK will navigate current app to SDK navigation page and start OAuth in WebBrowser. /// </summary> /// <param name="scopeList">List of permissions for your app</param> /// <param name="revoke">If true user will be allowed to logout and change user</param> /// <param name="forceOAuth">SDK will use only OAuth authorization via WebBrowser</param> public static void Authorize(List <String> scopeList, bool revoke = false, bool forceOAuth = false) { try { CheckConditions(); } catch (Exception e) { Debug.WriteLine(e.ToString()); return; } if (scopeList == null) { scopeList = new List <string>(); } // Force OFFLINE scope using if (!scopeList.Contains(VKScope.OFFLINE)) { scopeList.Add(VKScope.OFFLINE); } RootFrame.Navigate(new Uri(string.Format("/VK.WindowsPhone.SDK;component/Pages/VKLoginPage.xaml?Scopes={0}&Revoke={1}", string.Join(",", scopeList), revoke), UriKind.Relative)); }
private void _mpvm_CommandOperation(object sender, CommandArgs args) { switch (args.Command) { case "Operation": switch (args.Parameter.ToString()) { case "Exit": App.Current.Shutdown(); break; case "Show": App.Current.MainWindow.Show(); break; case "About": App.Current.MainWindow.Show(); RootFrame.Navigate(new Uri(ConstTable.PagePath + "AboutPage.xaml", UriKind.Relative)); break; } break; case "Nvigate": RootFrame.Navigate(new Uri(ConstTable.PagePath + args.Parameter.ToString(), UriKind.Relative)); break; } }
/// <summary> /// Global handler for when a Navigation happens /// </summary> /// <param name="sender">The object causing the navigation</param> /// <param name="e">Arguments pased in as part of navigation</param> private void RootFrameNavigated(object sender, NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.New && e.Uri.ToString().Contains("BackNavSkipOne=True")) { RootFrame.RemoveBackEntry(); } }
// Code to execute on Unhandled Exceptions private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (Debugger.IsAttached) { // // An unhandled exception has occurred; break into the debugger Debugger.Break(); } else { var rootSource = RootVisual as TransitionFrame; if (rootSource != null) { SetAppErrorMessage(e.ExceptionObject); rootSource.Source = new Uri("/Error.xaml", UriKind.Relative); } else { SetAppErrorMessage(e.ExceptionObject); RootFrame.Navigate(new Uri("/Error.xaml", UriKind.Relative)); } GlobalLoading.Instance.IsLoading = false; e.Handled = true; } }
private void BackRequested(object sender, BackRequestedEventArgs e) { if (RootFrame.CanGoBack) { RootFrame.GoBack(); } }
/// <summary> /// Call this method to save the navigation history along with session state locally. On failure, the Last Saved date is set to default (of the data type). /// </summary> /// <returns></returns> public static async Task SaveSessionState() { try { LastSessionSavedDate = default(DateTimeOffset); LastSessionOwner = null; PageStates.Add((_currentPage as IManageable).SaveState()); StorageFile navFile = await _folder.CreateFileAsync(NAV_FILE_NAME, CreationCollisionOption.ReplaceExisting); StorageFile stateFile = await _folder.CreateFileAsync(STATE_FILE_NAME, CreationCollisionOption.ReplaceExisting); bool result = true; result &= await StorageHelper.TryWriteAsync(navFile, RootFrame.GetNavigationState()); result &= await StorageHelper.TryWriteAsync(stateFile, PageStates); if (result == true) { LastSessionSavedDate = DateTimeOffset.UtcNow; LastSessionOwner = UserManager.CurrentUser.RegNo; } } catch { } }
private void OnBackRequested(object sender, BackRequestedEventArgs e) { if (App.OverrideBackEvent) { e.Handled = true; } else { if (RootFrame.SourcePageType == typeof(BlankPage)) { RootFrame.BackStack.Clear(); RootFrame.Navigate(typeof(HomeView)); e.Handled = true; } else { if (RootFrame.CanGoBack) { RootFrame.GoBack(); e.Handled = true; } else { RootFrame.Navigate(typeof(HomeView)); e.Handled = true; } } } }
private void OnBackRequested(object sender, BackRequestedEventArgs e) { if (App.OverrideBackEvent) { e.Handled = true; } else { if (RootFrame.SourcePageType == typeof(BlankView)) { RootFrame.BackStack.Clear(); RootFrame.Navigate(SoundByteV3Service.Current.IsServiceConnected(ServiceType.SoundCloud) ? typeof(SoundCloudStreamView) : typeof(ExploreView)); e.Handled = true; } else { if (RootFrame.CanGoBack) { RootFrame.GoBack(); e.Handled = true; } else { RootFrame.Navigate(SoundByteV3Service.Current.IsServiceConnected(ServiceType.SoundCloud) ? typeof(SoundCloudStreamView) : typeof(ExploreView)); e.Handled = true; } } } }
public MainPage() { this.InitializeComponent(); // Initialize auth state to false SetAuthState(false); // Load OAuth settings var oauthSettings = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView("OAuth"); var appId = oauthSettings.GetString("AppId"); var scopes = oauthSettings.GetString("Scopes"); if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(scopes)) { Notification.Show("Could not load OAuth Settings from resource file."); } else { // Initialize Graph MicrosoftGraphService.Instance.AuthenticationModel = MicrosoftGraphEnums.AuthenticationModel.V2; MicrosoftGraphService.Instance.Initialize(appId, MicrosoftGraphEnums.ServicesToInitialize.UserProfile, scopes.Split(' ')); // Navigate to HomePage.xaml RootFrame.Navigate(typeof(HomePage)); } }
/// <summary> /// hamburgerMenuItem选择事件 /// </summary> /// <param name="hamburgerMenuItem">HamburgerMenuItem</param> public void HamburgerMenu_ItemSelect(HamburgerMenuItem hamburgerMenuItem) { // 遍历,将选中Rectangle隐藏 foreach (var gameDataHamburgerMenuItem in _gameDataHamburgerMenuItem) { gameDataHamburgerMenuItem.Color = new SolidColorBrush(Colors.White); gameDataHamburgerMenuItem.Selected = Visibility.Collapsed; } foreach (var settingAndAboutHamburgerMenuItem in _settingAndAboutHamburgerMenuItem) { settingAndAboutHamburgerMenuItem.Color = new SolidColorBrush(Colors.White); settingAndAboutHamburgerMenuItem.Selected = Visibility.Collapsed; } hamburgerMenuItem.Selected = Visibility.Visible; hamburgerMenuItem.Color = new SolidColorBrush(Global.AccentColor); if (hamburgerMenuItem.NavigatePage != null) { RootFrame.Navigate(hamburgerMenuItem.NavigatePage); Global.PageStack.Push(new PageStackItem { TypeName = hamburgerMenuItem.NavigatePage }); Global.FrameTitle.Text = hamburgerMenuItem.Text; } }
private void Login_SignOutCompleted(object sender, EventArgs e) { // Set the auth state SetAuthState(false); // Reload the home page RootFrame.Navigate(typeof(HomePage)); }
private void NavMenuListView_ItemClick(object sender, ItemClickEventArgs e) { // 遍历,将选中Rectangle隐藏 foreach (var np in navMenuPrimaryItem) { np.Selected = Visibility.Collapsed; } foreach (var ns in navMenuSecondaryItem) { ns.Selected = Visibility.Collapsed; } NavMenuItem item = e.ClickedItem as NavMenuItem; // Rectangle显示并导航 item.Selected = Visibility.Visible; if (item.DestPage != null) { RootFrame.Navigate(item.DestPage); } RootSplitView.IsPaneOpen = false; myframe = RootFrame; mysplitView = RootSplitView; }
public MainPage() { this.InitializeComponent(); SizeChanged += MainPage_SizeChanged; if (ApiInformation.IsTypePresent(typeof(StatusBar).FullName)) { var bar = StatusBar.GetForCurrentView(); bar.BackgroundColor = Colors.PeachPuff; bar.ForegroundColor = Colors.White; // StatusBar.GetForCurrentView().HideAsync(); //Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow); ApplicationView.GetForCurrentView().VisibleBoundsChanged += MainPage_VisibleBoundsChanged; } else { } RootFrame.Navigated += RootFrame_Navigated; SystemNavigationManager.GetForCurrentView().BackRequested += BackButtonBackRequested;; ((App)App.Current).MainFrame = RootFrame; RootFrame.Navigate(typeof(Views.HomeView)); }
private void NaviView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) { NavigationViewItem item = args.SelectedItem as NavigationViewItem; switch (item.Content) { case "BBC": RootFrame.Navigate(typeof(Audio_BBC_Index_Page)); NaviViewTB.Text = "BBC英语"; break; case "VOA": RootFrame.Navigate(typeof(Audio_VOA_Index_Page)); NaviViewTB.Text = "VOA英语"; break; case "Video": RootFrame.Navigate(typeof(Video_Index_Page)); NaviViewTB.Text = "记录短片"; break; } if (item.Content.ToString().Contains("设置") == true) { RootFrame.Navigate(typeof(Setting_Page)); NaviViewSI.Symbol = Symbol.Setting; NaviViewTB.Text = "设置"; } }