コード例 #1
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            var LeftNavList  = new List <UIBarButtonItem>();
            var RightNavList = new List <UIBarButtonItem>();
            var ToolbarList  = new List <ToolbarItem>();

            UINavigationItem navigationItem = NavigationController.TopViewController.NavigationItem;

            // Add to new list for sorting
            foreach (ToolbarItem itm in Element.ToolbarItems)
            {
                ToolbarList.Add(itm);
            }

            // Sort the list
            ToolbarList.Sort((i1, i2) => { return(i1.Priority > i2.Priority ? -1 : 1); });

            foreach (ToolbarItem itm in ToolbarList)
            {
                if (itm.Priority < 0)
                {
                    LeftNavList.Add(itm.ToUIBarButtonItem());
                }
                else
                {
                    RightNavList.Add(itm.ToUIBarButtonItem());
                }
            }

            navigationItem.SetLeftBarButtonItems(LeftNavList.ToArray(), false);
            navigationItem.SetRightBarButtonItems(RightNavList.ToArray(), false);
        }
コード例 #2
0
        public static void UpdateBadgeCounter(UINavigationItem navigationItem, int numberOfPendingTasks)
        {
            var badgeButton = new UIButton(UIButtonType.Custom);

            badgeButton.SetImage(UIImage.FromFile("ic_number.png"), UIControlState.Normal);
            badgeButton.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
            badgeButton.ContentEdgeInsets     = new UIEdgeInsets(10f, 10f, 10f, 10f);
            badgeButton.TitleLabel.Font       = badgeButton.TitleLabel.Font.WithSize(14f);

            badgeButton.SetTitle(numberOfPendingTasks.ToString(), UIControlState.Normal);
            badgeButton.ImageEdgeInsets = new UIEdgeInsets(0, 0, 0, -45 - 10 * (badgeButton.TitleLabel.Text.Length - 1));

            var rightBarButton = new UIBarButtonItem(badgeButton);

            navigationItem.SetRightBarButtonItems(new UIBarButtonItem[] { rightBarButton }, false);
        }
コード例 #3
0
        private void ConfigureToolbarItems()
        {
            if (NavigationController != null)
            {
                UINavigationItem navigationItem = NavigationController.TopViewController.NavigationItem;
                var orderedItems = Element.ToolbarItems.OrderBy(x => x.Priority);

                // add right side items
                var rightItems = orderedItems.Where(x => x.Priority >= 0).Select(x => x.ToUIBarButtonItem()).ToArray();
                navigationItem.SetRightBarButtonItems(rightItems, false);

                // add left side items
                var leftItems = orderedItems.Where(x => x.Priority < 0).Select(x => x.ToUIBarButtonItem()).ToArray();
                //if (navigationItem.LeftBarButtonItems != null) // keep any already there(Bug, adds button multiple times)
                //    leftItems = navigationItem.LeftBarButtonItems.Union(leftItems).ToArray();
                navigationItem.SetLeftBarButtonItems(leftItems, false);
            }
        }
コード例 #4
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (((ContentPage)Element) == null || NavigationController == null)
            {
                return;
            }

            IList <ToolbarItem> toolbarItems = null;

            if (((Page)Element) is CalendarPage)
            {
                toolbarItems = ((CalendarPage)Element).ToolbarItems;
            }
            else
            {
                toolbarItems = ((AppointmentCreationPage)Element).ToolbarItems;
            }

            UINavigationItem       navigationItem = this.NavigationController.TopViewController.NavigationItem;
            List <UIBarButtonItem> leftButtons    = (navigationItem.LeftBarButtonItems ?? new UIBarButtonItem[] { }).ToList();
            List <UIBarButtonItem> rightButtons   = (navigationItem.RightBarButtonItems ?? new UIBarButtonItem[] { }).ToList();

            /* we handle it when OnElementChanged is invoked
             * secondaryButtons = new List<ToolbarItem>(toolbarItems.Where(item => item.Order == ToolbarItemOrder.Secondary));
             * foreach (var button in secondaryButtons)
             * {
             *  toolbarItems.Remove(button);
             * }*/

            /* If leftButtons.Count > 0 then buttons have already rearranged properly */
            if (leftButtons.Count == 0)
            {
                for (int i = 0; i < navigationItem.RightBarButtonItems.Length; i++)
                {
                    UIBarButtonItem newButton = null;
                    UIBarButtonItem button    = navigationItem.RightBarButtonItems[i];
                    if (toolbarItems[i].Priority == 0)
                    {
                        /* Buttons that should be in the left */
                        var buttonToRemove = rightButtons.FirstOrDefault();
                        if (buttonToRemove != null)
                        {
                            rightButtons.Remove(buttonToRemove);
                        }
                        if (IsSystemButton(button, ref newButton))
                        {
                            leftButtons.Add(newButton);
                        }
                        else
                        {
                            leftButtons.Add(button);
                        }
                    }
                    else
                    {
                        if (IsSystemButton(button, ref newButton))
                        {
                            var buttonToRemove = rightButtons.FirstOrDefault();
                            if (buttonToRemove != null)
                            {
                                rightButtons.Remove(buttonToRemove);
                            }
                            rightButtons.Add(newButton);
                        }
                    }
                }
            }

            /* initial version
             * for (int i = 0; i < toolbarItems.Count; i++)
             * {
             *  UIBarButtonItem newButton = null;
             *  UIBarButtonItem button = navigationItem.RightBarButtonItems[i];
             *  if (toolbarItems[i].Priority == 0) {
             *      if (IsSystemButton(button, ref newButton)) {
             *          leftButtons.Add(newButton);
             *      } else {
             *          leftButtons.Add(button);
             *      }
             *  } else {
             *      if (IsSystemButton(button, ref newButton)) {
             *          rightButtons.Add(newButton);
             *      } else {
             *          rightButtons.Add(button);
             *      }
             *  }
             * }*/

            navigationItem.SetRightBarButtonItems(rightButtons.ToArray(), false);
            navigationItem.SetLeftBarButtonItems(leftButtons.ToArray(), false);


            var secondaryButtonsNumber = secondaryButtons.Count;

            if (secondaryButtonsNumber > 0)
            {
                List <UIBarButtonItem> nativeSecondaryButtons = new List <UIBarButtonItem>();
                for (int i = 0, j = 0; i < secondaryButtonsNumber; i++, j++)
                {
                    if (i % 2 != 0 || (i != 0 && (i - 1) % 2 != 0))
                    {
                        UIBarButtonItem flexSpace = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
                        nativeSecondaryButtons.Add(flexSpace);
                        secondaryButtonsDict.Add(flexSpace, null);
                        j++;
                    }
                    nativeSecondaryButtons.Add(new UIBarButtonItem(secondaryButtons[i].Text, UIBarButtonItemStyle.Plain, TouchUpInside));
                    secondaryButtonsDict.Add(nativeSecondaryButtons[j], secondaryButtons[i]);
                }

                this.NavigationController.ToolbarHidden = false;
                toolbar = new UIToolbar(CGRect.Empty)
                {
                    Items = nativeSecondaryButtons.ToArray()
                };
                toolbar.TintColor = UIColor.FromRGB(24, 149, 132);
                NavigationController.View.Add(toolbar);
            }
        }