Ejemplo n.º 1
0
 /// <summary>
 /// 初次加载多页Tab,可用于动态选择Tab
 /// </summary>
 /// <param name="p_tabs"></param>
 protected virtual void OnInitPhoneTabs(PhoneTabs p_tabs)
 {
 }
Ejemplo n.º 2
0
        /// <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);
        }