public PhonePage() { // Control默认11,系统默认15 FontSize = 15; _param = _newParam; // 原来在OnNavigatedFrom方法中卸载内容以便下次重用,但会造成页面返回时无动画!!! // 因此再次加载时需要卸载旧页面的内容! // elem.Parent在uno中仍然有效,uwp中因不在可视树无值,通过附加属性记录所属页面! var elem = _param.Content as FrameworkElement; #if UWP PhonePage oldPage = PhonePageEx.GetParentPage(elem); if (oldPage != null) { oldPage.Content = null; } PhonePageEx.SetParentPage(elem, this); #else if (elem.Parent is PhonePage oldPage) { oldPage.Content = null; } #endif Content = elem; }
/// <summary> /// 向前导航到新内容 /// </summary> /// <param name="p_content"></param> void INaviHost.NaviTo(INaviContent p_content) { INaviContent current; if (p_content == null || (current = Content as INaviContent) == null) { return; } if (Kit.IsPhoneUI) { Tab tab = new Tab { OwnWin = OwnWin, Content = p_content }; PhonePage.Show(tab); return; } if (_naviCache == null) { _naviCache = new Stack <INaviContent>(); // 内容切换动画 var ls = new TransitionCollection(); ls.Add(new ContentThemeTransition { VerticalOffset = 60 }); OwnTabs.ContentTransitions = ls; } _naviCache.Push(current); Content = p_content; }
void LoadPhoneMain(object p_content) { // 未加载win的Home页前不导航 if (_tabs == null) { return; } // 内容相同也需导航 if (p_content is Win win) { win.NaviToHome(); } else { Tab tab = (Tab)GetValue(PhoneMainTabProperty); if (tab == null) { tab = new Tab(); SetValue(PhoneMainTabProperty, tab); } tab.Content = p_content; PhonePage.Show(tab); } }
/// <summary> /// 导航到单页Tab /// </summary> /// <param name="p_tab"></param> void NaviToSingleTab(Tab p_tab) { // 判断是否为向后导航 var frame = SysVisual.RootFrame; if (frame.BackStackDepth > _frameStartIndex) { // 向后查询 int index = -1; for (int i = frame.BackStackDepth - 1; i >= _frameStartIndex; i--) { var pageEntry = frame.BackStack[i]; if (pageEntry.Parameter is PhonePageParameter param && param.Content == p_tab) { // 后退位置 index = i; break; } } if (index > 0) { // 向后导航 for (int i = frame.BackStackDepth - 1; i >= index; i--) { if (frame.CanGoBack) { frame.GoBack(); } } return; } } // 起始页隐藏返回按钮 if (frame.Content == null) { p_tab.PinButtonVisibility = Visibility.Collapsed; } // 向前导航 PhonePage.Show(p_tab); }
/// <summary> /// 导航到多页Tab /// </summary> /// <param name="p_tabTitle"></param> void NaviToMultiTabs(string p_tabTitle) { // 判断是否为向后导航 var frame = SysVisual.RootFrame; if (frame.BackStackDepth > _frameStartIndex) { // 向后查询 int index = -1; for (int i = frame.BackStackDepth - 1; i >= _frameStartIndex; i--) { var pageEntry = frame.BackStack[i]; if (pageEntry.Parameter is PhonePageParameter param && param.Content is PhoneTabs pts && pts.NaviID == p_tabTitle) { // 后退位置 index = i; break; } } if (index > 0) { // 向后导航 for (int i = frame.BackStackDepth - 1; i >= index; i--) { if (frame.CanGoBack) { frame.GoBack(); } } return; } } // 向前导航 PhoneTabs tabs; if (_cacheMultiTabs != null) { tabs = (from t in _cacheMultiTabs where t.NaviID == p_tabTitle select t).FirstOrDefault(); if (tabs != null) { // 缓存中存在 PhonePage.Show(tabs); return; } } tabs = new PhoneTabs(); tabs.NaviID = p_tabTitle; if (p_tabTitle == Home) { tabs.OwnWin = this; } Tab tab; string[] names = p_tabTitle.Split(','); foreach (var name in names) { if (!_tabs.TryGetValue(name, out tab)) { throw new Exception($"导航出错,缺少{name}Tab页!"); } tabs.AddItem(tab); } // 起始页隐藏返回按钮 if (frame.Content == null) { tabs.HideBackButton(); } tabs.Select(0); if (_cacheMultiTabs == null) { _cacheMultiTabs = new List <PhoneTabs>(); } _cacheMultiTabs.Add(tabs); OnInitPhoneTabs(tabs); PhonePage.Show(tabs); }