public static async Task<ViewLifetimeControl> CreateInNewViewAsync(string seriesTitle, NovelPositionIdentifier nav) { ViewLifetimeControl viewControl = null; await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { // This object is used to keep track of the views and important // details about the contents of those views across threads // In your app, you would probably want to track information // like the open document or page inside that window viewControl = ViewLifetimeControl.CreateForCurrentView(); viewControl.Title = seriesTitle; AppGlobal.SecondaryViews.Add(viewControl); CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; var appView = ApplicationView.GetForCurrentView(); appView.Title = viewControl.Title; appView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow); var titleBar = appView.TitleBar; titleBar.BackgroundColor = Colors.Transparent; titleBar.ButtonBackgroundColor = (Color)App.Current.Resources["AppAccentColor"]; titleBar.ButtonInactiveBackgroundColor = (Color)App.Current.Resources["AppAccentColor"]; await Task.Delay(TimeSpan.FromMilliseconds(200)); var frame = new Frame(); Window.Current.Content = frame; frame.Navigate(typeof(ReadingPage), nav.ToString()); var readingPage = frame.Content as ReadingPage; if (readingPage != null) viewControl.Released += readingPage.ViewControl_Released; //ApplicationView.GetForCurrentView().Consolidated += readingPage.ReadingPage_Consolidated; //viewControl.StartViewInUse(); }); return viewControl; }
async Task NavigateToReadingPageAsync(string seriesTitle, NovelPositionIdentifier nav, bool newWindows = false) { #if WINDOWS_APP || WINDOWS_UWP var view = AppGlobal.SecondaryViews.FirstOrDefault(v => v.Title == seriesTitle); if (view == null && !newWindows) this.Frame.Navigate(typeof(ReadingPage), nav.ToString()); else try { if (view == null) { view = await ReadingPage.CreateInNewViewAsync(seriesTitle,nav); } // Prevent the view from closing while // switching to it view.StartViewInUse(); // Show the previously created secondary view, using the size // preferences the user specified. In your app, you should // choose a size that's best for your scenario and code it, // instead of requiring the user to decide. var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync( view.Id, ViewSizePreference.Default, ApplicationView.GetForCurrentView().Id, ViewSizePreference.Default); if (!viewShown) { this.Frame.Navigate(typeof(ReadingPage), nav.ToString()); } // Signal that switching has completed and let the view close view.StopViewInUse(); } catch (InvalidOperationException) { Debug.WriteLine("Some thing wrong"); } #else this.Frame.Navigate(typeof(ReadingPage), nav.ToString()); #endif }