예제 #1
0
        private void ChildrenView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            MorePageItem item = e.SelectedItem as MorePageItem;

            if (item != null)
            {
                // Tell PageItem to execute the registered Action (typically: open page).
                item.OnClicked();
            }
            ChildrenView.SelectedItem = null;
        }
예제 #2
0
        private void TabPages_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                foreach (var item in e.NewItems)
                {
                    TabPage tabPage = item as TabPage;
                    if (TabPages.Count < MaxTabs + 1)
                    {
                        this.Children.Add(tabPage);
                    }
                    else
                    {
                        // Can't show the page
                        // Add page as a child to MorePage
                        MorePageItem pageItem = new MorePageItem(tabPage,
                                                                 () =>
                            {
                                ContentPage newPage = tabPage.CreateContentPageInstance();
                                Navigation.PushAsync(newPage);
                            });
                        // Check if it must be presented in 'MorePage' or in a dropdown list
                        if (MorePagesMode == MorePagesAccessMode.MorePage)
                        {
                            // Must be shown under 'More' page list.
                            if (TabPages.Count == MaxTabs + 1)
                            {
                                // This is the first page to be added.
                                // Add a MorePage tabPage in case of iOS and a MorePage toolbaricon otherwise
                                string moreTitle = string.IsNullOrEmpty(MorePageTitle) ? "More" : MorePageTitle;
                                _morePage = new MorePage(moreTitle);
                                if (Device.RuntimePlatform == Device.iOS)
                                {
                                    this.Children.Add(_morePage);
                                }
                                else
                                {
                                    var moreToolbarItem = new ToolbarItem(moreTitle, MoreToolbarIcon,
                                                                          () =>
                                        {
                                            Navigation.PushAsync(_morePage);
                                        }, Device.RuntimePlatform == Device.Android ? ToolbarItemOrder.Primary : ToolbarItemOrder.Primary, 100);
                                    SetMoreToolbarItem(moreToolbarItem);
                                }
                            }
                            _morePage.MorePageItems.Add(pageItem);
                        }
                        else
                        {
                            // Must be shown in the 'More' popupmenu list.
                            if (TabPages.Count == MaxTabs + 1)
                            {
                                // This is the first page to be added.
                                // Add a 'More' popupmenu toolbaricon
                                string moreTitle       = string.IsNullOrEmpty(MorePageTitle) ? "More" : MorePageTitle;
                                var    moreToolbarItem = new ToolbarItem(moreTitle, MoreToolbarIcon,
                                                                         async() =>
                                    {
                                        // Show PopupMenu
                                        if (_activeTabPage != null &&
                                            _activeTabPage.ContentBaseLayout != null)
                                        {
                                            try
                                            {
                                                var menuPopup = new MorePopupMenuPage(MorePopupMenuItems,
                                                                                      MorePopupMenuMargin,
                                                                                      MorePopupMenuItemHeigth)
                                                {
                                                    MenuItemSelectedBackgroundColor = MorePopupMenuItemSelectedBackgroundColor,
                                                    MenuItemTextColor           = MorePopupMenuItemTextColor,
                                                    MenuItemSeperatorColor      = MorePopupMenuItemSeperatorColor,
                                                    MenuItemSeperatorVisibility = MorePopupMenuItemSeperatorVisibility,
                                                    MenuBackgroundColor         = MorePopupMenuBackgroundColor,
                                                };
                                                await Navigation.PushPopupAsync(menuPopup);
                                            }
                                            catch (Exception ex)
                                            {
                                                throw new Exception("Please install nuget package rg.plugins.popup");
                                            }
                                        }
                                    }, ToolbarItemOrder.Primary, 100);
                                SetMoreToolbarItem(moreToolbarItem);
                            }
                            MorePopupMenuItems.Add(pageItem);
                        }
                    }
                }
                break;
            }

            case NotifyCollectionChangedAction.Remove:
                int pageStartIdx = e.OldStartingIndex;
                foreach (var item in e.OldItems)
                {
                    TabPage tabPage = item as TabPage;
                    // Check if removed page was visible
                    if (this.Children.Contains(tabPage))
                    {
                        // Yes
                        this.Children.Remove(tabPage);
                        int mTabs = (Device.RuntimePlatform == Device.iOS) ? MaxTabs + 1 : MaxTabs;
                        if (!DontMovePages &&
                            this.Children.Count < mTabs)
                        {
                            // We can bring the first hidden page to the main view.
                            // Check if this page is under "MorePage" or under "MorePopupMenu"
                            if (MorePagesMode == MorePagesAccessMode.MorePage)
                            {
                                // Page is under 'More'.
                                // Remove it under "More"
                                _morePage.MorePageItems.RemoveAt(0);
                                // Check if there are still other pages under "More"
                                if (_morePage.MorePageItems.Count == 0)
                                {
                                    // No: Remove MorePage tabPage in case of iOS and the MorePage toolbar item otherwise
                                    if (Device.RuntimePlatform == Device.iOS)
                                    {
                                        this.Children.Remove(_morePage);
                                        _morePage = null;
                                    }
                                    else
                                    {
                                        ResetMoreToolbarItem();
                                    }
                                }
                            }
                            else
                            {
                                // First hidden page is in MorePopupMenu
                                MorePopupMenuItems.RemoveAt(0);
                                // Check if there are still other pages under "More"
                                if (MorePopupMenuItems.Count == 0)
                                {
                                    // No: Remove the MorePopupMenu toolbar item
                                    ResetMoreToolbarItem();
                                }
                            }
                            // Bring in the hidden tab page
                            var hiddenPage  = this.TabPages[MaxTabs - 1];
                            int insertIndex = (Device.RuntimePlatform == Device.iOS) ? MaxTabs - 1 : MaxTabs;
                            this.Children.Insert(insertIndex, hiddenPage);
                        }
                    }
                    else if (_morePage != null)
                    {
                        // No, removed page was under "MorePage"
                        var itemPage = _morePage.MorePageItems.FirstOrDefault(i => i.TabPage == tabPage);
                        if (itemPage != null)
                        {
                            _morePage.MorePageItems.Remove(itemPage);
                        }
                        if (TabPages.Count == MaxTabs + 1)
                        {
                            if (Device.RuntimePlatform == Device.iOS)
                            {
                                this.Children.Remove(_morePage);
                                _morePage = null;
                            }
                            else
                            {
                                ResetMoreToolbarItem();
                            }
                        }
                    }
                    else
                    {
                        // No, removed page was under MorePopupMenu
                        var entry = MorePopupMenuItems.FirstOrDefault(p => p.TabPage == tabPage);
                        if (entry != null)
                        {
                            MorePopupMenuItems.Remove(entry);
                            // Remove MorePopupMenu toolbar item if there are no pages anymore in MorePopupMenu
                            if (MorePopupMenuItems.Count == 0)
                            {
                                ResetMoreToolbarItem();
                            }
                        }
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                this.Children.Clear();
//                    this.ToolbarItems.Clear();
                this.MorePopupMenuItems.Clear();
                if (_morePage != null)
                {
                    _morePage.MorePageItems.Clear();
                }
                _moreToolbarItem = null;
                _morePage        = null;
                break;
            }
        }