示例#1
0
 /// <summary>
 /// 显示一个用户自定义UI页到UIFrame
 /// </summary>
 /// <param name="uiPageName">页面的名字</param>
 /// <returns>页面是否存在</returns>
 public static bool ShowUIPage(string uiPageName)
 {
     try
     {
         var up = ViewPageManager.RetrievePage(uiPageName);
         if (up == null)
         {
             if (ViewPageManager.typeDict.ContainsKey(uiPageName))
             {
                 var pageType = ViewPageManager.typeDict[uiPageName];
                 var pageObj  = (Page)Activator.CreateInstance(pageType);
                 ViewPageManager.RegisterPage(uiPageName, pageObj);
                 ViewManager.mWnd.uiFrame.Visibility = System.Windows.Visibility.Visible;
                 ViewManager.mWnd.uiFrame.Content    = pageObj;
                 return(true);
             }
             return(false);
         }
         ViewManager.mWnd.uiFrame.Visibility = System.Windows.Visibility.Visible;
         ViewManager.mWnd.uiFrame.Content    = up;
         return(true);
     }
     catch (Exception ex)
     {
         LogUtils.LogLine("Show UI Page in uiframe failed. " + ex, "ViewPageManager", LogLevel.Error);
         return(false);
     }
 }
示例#2
0
        /// <summary>
        /// 导航到目标页面
        /// </summary>
        /// <param name="toPageName">目标页面在页管理器里的唯一标识符</param>
        public static void NavigateTo(string toPageName)
        {
            // 不在主舞台就不处理调用堆栈
            if ((ViewPageManager.CurrentPage is PageView.Stage2D || ViewPageManager.CurrentPage is PageView.Stage3D) &&
                toPageName != GlobalConfigContext.FirstViewPage)
            {
                Director.PauseUpdateContext();
            }
            var rp = ViewPageManager.RetrievePage(toPageName);

            try
            {
                if (rp != null && ViewPageManager.CurrentPage != null)
                {
                    NavigationService.GetNavigationService(ViewPageManager.CurrentPage)?.Navigate(rp);
                    ViewPageManager.PageCallStack.Push(rp);
                }
                else
                {
                    LogUtils.LogLine(string.Format("Cannot find page: {0}, Navigation service ignored.", toPageName),
                                     "ViewPageManager", LogLevel.Error);
                    Director.GetInstance().GetMainRender().Shutdown();
                }
            }
            catch (Exception ex)
            {
                LogUtils.LogLine(string.Format("Cannot find page: {0}, Navigation service ignored. {1}", toPageName, ex),
                                 "ViewPageManager", LogLevel.Error);
                Director.GetInstance().GetMainRender().Shutdown();
            }
            // 如果目标页是主舞台就恢复处理调用堆栈
            if (toPageName == GlobalConfigContext.FirstViewPage)
            {
                Director.ResumeUpdateContext();
            }
        }