コード例 #1
0
        public MAppBar(EvasObject parent) : base(parent)
        {
            MaterialComponents.VerifyComponentEnabled(this);

            AlignmentX    = -1;
            WeightX       = 1;
            MinimumHeight = DefaultValues.AppBar.Height;

            _box = new Box(this)
            {
                AlignmentX = -1,
                AlignmentY = -1,
                WeightX    = 1,
                WeightY    = 1
            };
            SetContent(_box);

            _naviButton = new MButton(_box);

            _items.CollectionChanged += OnItemsCollectionChanged;
            _box.SetLayoutCallback(() => { UpdateChildrenGeometry(); });

            MColors.AddColorSchemeComponent(this);
        }
コード例 #2
0
        protected virtual void UpdateActionButtons()
        {
            ResetItems();

            for (int i = 0; i < ActionItems.Count; i++)
            {
                var button = new MButton(_box);
                var item   = ActionItems[i];

                if (i < VisibleItemCount)
                {
                    if (!string.IsNullOrEmpty(item.IconPath))
                    {
                        var icon = new Image(_box);
                        icon.Load(item.IconPath);
                        button.Icon = icon;
                    }

                    button.Clicked += (s, e) =>
                    {
                        (item as IMActionItemController)?.Activate();
                    };

                    _actionButtons.Add(button);
                }
                else if (i == VisibleItemCount)
                {
                    var moreIcon = new Image(_box);
                    var stream   = Assembly.GetExecutingAssembly().GetManifestResourceStream(DefaultValues.AppBar.MoreIconPath);
                    moreIcon.Load(stream);
                    button.Icon = moreIcon;

                    if (_moreitemsMenus == null)
                    {
                        _moreitemsMenus = new MMenus(this.Parent);
                    }

                    var popupItem = _moreitemsMenus.Append(item.Text);
                    popupItem.Selected += (sender, args) =>
                    {
                        (item as IMActionItemController)?.Activate();
                        _moreitemsMenus.Hide();
                    };

                    button.Clicked += (s, e) =>
                    {
                        _moreitemsMenus.Show();
                        var moveY = button.Geometry.Y;
                        if (OverflowPopupToDown)
                        {
                            moveY += (button.Geometry.Height + _moreitemsMenus.Geometry.Height + 5);
                        }
                        else
                        {
                            moveY -= 5;
                        }
                        _moreitemsMenus.Move(button.Geometry.X, moveY);
                    };

                    _actionButtons.Add(button);
                }
                else
                {
                    var popupItem = _moreitemsMenus.Append(item.Text);
                    popupItem.Selected += (sender, args) =>
                    {
                        (item as IMActionItemController)?.Activate();
                        _moreitemsMenus.Hide();
                    };
                }
            }
        }