public Grid GetCurrentAnimationGrid() { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { Grid grid = CoreVisualTreeHelper.Instance.FindVisualChildByName <Grid>(rootFrame.Content as Page, "AnimationGrid"); if (grid != null) { return(grid); } else { return(null); } } else { return(null); } } else { return(null); } }
public ListView GetCurrentFavoriteListView() { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { ListView lv = CoreVisualTreeHelper.Instance.FindVisualChildByName <ListView>(rootFrame.Content as Page, "szListView"); if (lv != null) { return(lv); } else { return(null); } } else { return(null); } } else { return(null); } }
public SemanticZoom GetCurrentSemanticZoom(string name) { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { SemanticZoom sz = CoreVisualTreeHelper.Instance.FindVisualChildByName <SemanticZoom>(rootFrame.Content as Page, name); if (sz != null) { return(sz); } else { return(null); } } else { return(null); } } else { return(null); } }
private void grid_Tapped(object sender, TappedRoutedEventArgs e) { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { Page page = rootFrame.Content as Page; if (page != null) { ListView szListView = page.FindName("szListView") as ListView; if (szListView != null) { var scroll = VisualTreeHelperEx.FindVisualChildByName <ScrollViewer>(szListView, "ScrollViewer"); if (scroll != null) { scroll.ScrollToVerticalOffset(0); } } } } } }
private Frame GetRootFrame() { Frame rootFrame; NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage == null) { rootPage = new NavigationRootPage(); rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame == null) { throw new Exception("Root frame not found"); } //SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; Window.Current.Content = rootPage; } else { rootFrame = (Frame)rootPage.FindName("rootFrame"); } return(rootFrame); }
private async Task ShowWindow(LaunchActivatedEventArgs e) { //获取并记录屏幕宽度,一定要在程序启动的时候记录,这样记录到的数据才是竖屏下的屏幕高度。屏幕旋转Window.Current.Bounds.With宽高会互换 AppEnvironment.ScreenPortraitWith = Window.Current.Bounds.Width; //初始化线程 GalaSoft.MvvmLight.Threading.DispatcherHelper.Initialize(); NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; // 不要在窗口已包含内容时重复应用程序初始化, // 只需确保窗口处于活动状态 if (rootPage == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootPage = new NavigationRootPage(); Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } // 将框架放在当前窗口中 Window.Current.Content = rootPage; //初始化手机和平板的背景颜色资源 InitColors(); // 确保当前窗口处于活动状态 Window.Current.Activate(); WelcomeBox.Instance.ShowWelcome(); await Task.Delay(2150); if (rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 rootFrame.Navigate(typeof(NewsPage), "情报站"); } } }
private async Task ShowWindow(LaunchActivatedEventArgs e) { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootPage == null) { rootPage = new NavigationRootPage(); // Retrieve the root Frame to act as the navigation context and navigate to the first page Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame == null) { throw new Exception("Root frame not found"); } // Associate the frame with a SuspensionManager key. SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); // Set the default language rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page. rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Place the main page in the current Window. Window.Current.Content = rootPage; } // Ensure the current window is active Window.Current.Activate(); }
public void ClearFrameBackStack() { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { rootFrame.BackStack.Clear(); } } }
private void UIControlBase_Loaded(object sender, RoutedEventArgs e) { rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { //rootFrame.SizeChanged -= RootFrame_SizeChanged; rootFrame.SizeChanged += RootFrame_SizeChanged; } } }
public TextBlock GetRootPageSubTitle() { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { var tb = (TextBlock)rootPage.FindName("tbSubTitle"); return(tb); } else { return(null); } }
public Microsoft.PlayerFramework.MediaPlayer GetCurrentPlayerFramework() { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { Microsoft.PlayerFramework.MediaPlayer mp = CoreVisualTreeHelper.Instance.FindVisualChildByName <Microsoft.PlayerFramework.MediaPlayer>(rootFrame.Content as Page, "videoMediaPlayer"); //int count = 0; //while(mp == null) //{ // mp = CoreVisualTreeHelper.Instance.FindVisualChildByName<Microsoft.PlayerFramework.MediaPlayer>(rootFrame.Content as Page, "videoMediaPlayer"); // if (mp != null) // { // Debug.WriteLine("我找到了,耗时:" + ++count * 1 + "毫秒"); // break; // } // else // { // await Task.Delay(1); // } //} if (mp != null) { return(mp); } else { return(null); } } else { return(null); } } else { return(null); } }
public void NavigateWithOverride(Type t, object parameter = null) { NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { Frame rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { if (parameter != null) { rootFrame.Navigate(t, parameter); } else { rootFrame.Navigate(t); } } } }
private void grid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { if (e.IsInertial) { int threshold = -40; Debug.WriteLine(start.X); if (start.X - e.Position.X < threshold) //swipe left { e.Complete(); Debug.WriteLine("我被触发了"); NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { rootPage.splitViewToggleButton_Click(null, null); } } } }
public UIControlBase() { this.Loaded += (ss, ee) => { this.PointerPressed += UIControlBase_PointerPressed; this.PointerExited += UIControlBase_PointerExited; this.PointerReleased += UIControlBase_PointerReleased; this.PointerCaptureLost += UIControlBase_PointerCaptureLost; this.Tapped += UIControlBase_Tapped; rootPage = Window.Current.Content as NavigationRootPage; if (rootPage != null) { rootFrame = (Frame)rootPage.FindName("rootFrame"); if (rootFrame != null) { //rootFrame.SizeChanged -= RootFrame_SizeChanged; rootFrame.SizeChanged += RootFrame_SizeChanged; } } }; this.Unloaded += (ss, ee) => { this.PointerPressed -= UIControlBase_PointerPressed; this.PointerExited -= UIControlBase_PointerExited; this.PointerReleased -= UIControlBase_PointerReleased; this.PointerCaptureLost -= UIControlBase_PointerCaptureLost; this.Tapped -= UIControlBase_Tapped; if (rootPage != null) { if (rootFrame != null) { rootFrame.SizeChanged -= RootFrame_SizeChanged; } } }; }
private async Task ShowWindow(LaunchActivatedEventArgs e) { //获取并记录屏幕宽度,一定要在程序启动的时候记录,这样记录到的数据才是竖屏下的屏幕高度。屏幕旋转Window.Current.Bounds.With宽高会互换 AppEnvironment.ScreenPortraitWith = Window.Current.Bounds.Width; //初始化MvvmLight线程 GalaSoft.MvvmLight.Threading.DispatcherHelper.Initialize(); NavigationRootPage rootPage = Window.Current.Content as NavigationRootPage; Frame rootFrame = null; // 不要在窗口已包含内容时重复应用程序初始化, // 只需确保窗口处于活动状态 if (rootPage == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootPage = new NavigationRootPage(); rootFrame = (Frame)rootPage.FindName("rootFrame"); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } //如果是手机,则默认全屏模式 if (AppEnvironment.IsPhone) { ApplicationView.GetForCurrentView().TryEnterFullScreenMode(); //ApplicationView.GetForCurrentView().TitleBar } else { // DisplayProperties.CurrentOrientation 发生变化时触发的事件 //设置平板窗口的最小宽高 ApplicationView.GetForCurrentView().SetPreferredMinSize(AppEnvironment.DesktopSize); } //初始化数据库 await InitDatabase(); //获取数据库数据 await GetDatabaseCollection(); //处理自定义SplashScreenImage var isLoadSplashImageSuccess = await InitSplashScreenImage(); //如果SplashScreenI加载失败,则不显示欢迎屏幕,直接进入主界面 if (isLoadSplashImageSuccess) { //存储第一次启动的表示,是为了防止DailyPage第一页加载数据的时候把ProgressUIControl或者RetryUIControl显示出来,达到正确显示的逻辑处理 DicStore.AddOrUpdateValue <bool>(AppCommonConst.IS_APP_FIRST_LAUNCH, true); //这句话放在Activate()之前是为了保证在系统的初始屏幕SplashScreen.png消失之后能够显示ShowWelcome的内容。这是正确的处理逻辑 WelcomeBox.Instance.ShowWelcome(); } //这句话调用以后,在Package.appxmanifest文件配置的初始屏幕SplashScreen.png就会消失。不写这句话的话,会一直停留显示在初始屏幕SplashScreen.png处。因此,自定义SplashScreenImage的处理逻辑应该放在这句话之前 //确保当前窗口处于活动状态 Window.Current.Activate(); //这个放在Activate()方法下面是为了防止在ShowWelcome没显示之前Window.Current.Content就显示出来的问题。因为只要写了这句话,rootPage就会立刻被激活显示,此时的ShowWelcome可能还没显示出来,造成闪一下的问题。放在ShowWelcome()和Activate()之后才是正确的处理逻辑。 // 将框架放在当前窗口中 Window.Current.Content = rootPage; } if (rootFrame != null && rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 rootFrame.Navigate(typeof(DailyPage), "每日精选"); } Window.Current.Activate(); }