public async Task TestSendTargetSelected()
        {
            var menu    = new NavigationMenu();
            var navForm = new NavigationPage();

            await navForm.PushAsync(new ContentPage {
                Title   = "Menu",
                Content = menu
            });

            bool pushed = false;

            navForm.Pushed += (sender, arg) => pushed = true;

            var child = new ContentPage {
                Icon    = "img.jpg",
                Content = new View()
            };

            menu.Add(child);

            menu.SendTargetSelected(child);

            Assert.True(pushed);
            Assert.AreEqual(child, navForm.CurrentPage);
        }
Ejemplo n.º 2
0
            public override AView GetView(int position, AView convertView, ViewGroup parent)
            {
                MenuElementView menuItem = convertView as MenuElementView ?? new MenuElementView(parent.Context);
                Page            item     = this[position];

                menuItem.Icon       = item.Icon;
                menuItem.Name       = item.Title;
                menuItem.OnSelected = () => _menu.SendTargetSelected(item);
                return(menuItem);
            }
            public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
            {
                var cell   = (NavigationCell)collectionView.DequeueReusableCell(new NSString("NavigationCell"), indexPath);
                var target = _menu.Targets.Skip(indexPath.Row).FirstOrDefault();

                if (target != null)
                {
                    cell.Name     = target.Title;
                    cell.Icon     = target.Icon;
                    cell.Selected = () => _menu.SendTargetSelected(target);
                }
                else
                {
                    cell.Selected = null;
                    cell.Icon     = "";
                    cell.Name     = "";
                }

                return(cell);
            }
Ejemplo n.º 4
0
            public override NSCollectionViewItem GetItem(NSCollectionView collectionView, NSIndexPath indexPath)
            {
                // No view recycling on Mac
                //var navigationCell = (NavigationMenuRenderer.NavigationCell)collectionView.DequeueReusableCell (new NSString ("NavigationCell"), indexPath);
                var navigationCell = new NavigationMenuRenderer.NavigationCell(collectionView.Frame);

                var target = menu.Targets.Skip((int)indexPath.Item).FirstOrDefault();

                if (target != null)
                {
                    navigationCell.Name     = target.Title;
                    navigationCell.Icon     = (string)target.Icon;
                    navigationCell.Selected = (Action)(() => menu.SendTargetSelected(target));
                }
                else
                {
                    navigationCell.Selected = (Action)null;
                    navigationCell.Icon     = "";
                    navigationCell.Name     = "";
                }
                return(navigationCell);
            }