コード例 #1
0
        /// <summary>
        /// 添加新的页面
        /// </summary>
        /// <param name="page">页面源,使用new Pages.xxx()初始化</param>
        /// <param name="title">页面标题</param>
        /// <returns>返回初始化后的Page</returns>
        public static Page AddPage(Page page, string title)
        {
            pages.Add(UUIDTemp, page);
            var PageInfo = new PageItemModel()
            {
                PageTitle = title, PageSource = page, uuid = UUIDTemp
            };

            UUIDTemp         = CreateNewUUID;
            page.DataContext = PageInfo;
            PageItems.Add(PageInfo);
            Dispatcher.CurrentDispatcher.Invoke(() => (Application.Current.MainWindow as MainWindow).ListView_Page.SelectedIndex = PageItems.Count - 1);
            //if (page is Pages.ProcessContainer)
            //{
            //    throw new Exception((page as Pages.ProcessContainer).StPar.ToString());
            //}
            return(page);
        }
コード例 #2
0
        /// <summary>
        /// 替换Page
        /// </summary>
        /// <param name="uuid">目标Page的UUID</param>
        /// <param name="page">替换成的Page,使用new Pages.xxx()初始化</param>
        /// <param name="title">替换后的Page标题</param>
        /// <returns>返回替换后的Page的位置</returns>
        public static int ReplacePage(string uuid, Page page, string title)
        {
            //清除旧Page
            pages[uuid].Content = null;
            //创建新Page的信息
            var PageInfo = new PageItemModel()
            {
                PageTitle = title, PageSource = page, uuid = uuid
            };

            page.DataContext = PageInfo;
            int index = PageItems.IndexOf(PageItems.First(l => l.uuid == uuid));

            PageItems[index] = PageInfo;
            Dispatcher.CurrentDispatcher.Invoke(() =>
            {
                //(Application.Current.MainWindow as MainWindow).ListView_Page.Items[index] = PageInfo;
                (Application.Current.MainWindow as MainWindow).ListView_Page.SelectedIndex = index;
            });
            GC.Collect();
            //返回Page的Index
            return(index);
        }