How to add drop down menu to ribbon group

Attached is a sample project that demo adding drop down menu to VC 4.0 ribbon group.

Plugin.DropDownMenuInRibbon.zip (59.1 KB)

1 Like

Good work !

Hi, Jay.

I was trying to implement a drop-down menu with checkboxes, but could not succeed. It was supposed to be something like the image below.

 

Here is what I wrote.

[Export(typeof(IActionItem))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class APCheckBoxSideApproach : ActionItem
    {
        public APCheckBoxSideApproach()
        : base("APCheckBoxSideApproach", " Pick Type ", "PickIcon", null, MenuTools.ButtonMenuTool, true)
        {
            this.ContextFilter = Contexts.All;

            //Title and tooltip for control
            this.ToolTipVisibility = System.Windows.Visibility.Visible;
            this.ToolTipHeader = "Pick type";
            this.ToolTipContent = "Select what pick type to use.";
            //determine control availability
            this.CreateMenuItems();
            this.canExecute = (() => true);

        }

        APCheckBoxTopApproach topPick = new APCheckBoxTopApproach();

        // IMenuTooCommand members
        private BindableCollection<ActionItem> _items = new BindableCollection<ActionItem>();
        public System.Collections.ObjectModel.ObservableCollection<ActionItem> MenuItems
        {  get { return _items; } }

        public static bool isChecked;
        public bool IsChecked { get { return isChecked; } set { isChecked = value; } }

        //Add items to Menu
        void CreateMenuItems()
        {       
            _items.Add(topPick);
        }

        public void Execute()
        {
            IoC.Get<IMessageService>().AppendMessage("Fine", MessageLevel.Warning);
        }
    
    }


    [Export(typeof(IActionItem))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    internal class APCheckBoxTopApproach : ActionItem
    {
        public APCheckBoxTopApproach()
        : base("APCheckBoxTopApproach", " Top Pick ", "", null, MenuTools.CheckBoxTool, true)
        {
            //Title and tooltip for control
            ToolTipHeader = "Top Picking Approach";
            ToolTipFooter = "Enable/Disable Top picking approach.";
        }

        public static bool isChecked;
        public bool IsChecked
        {
            get
            {
                return isChecked;
            }
            set
            {
                isChecked = value;
            }
        }

        public bool Execute()
        {
            return IsChecked;
        }

    }

I click the checkbox, it call the Execute method, but it does not get checked.

@andreluizfc

I don’t see where you are calling EvaluateCanExecute() nor binding menu items to events.

MenuItemBase menu_item = new MenuItemBase(direction.ToString(), direction.ToString(), “”, this);
menu_item.AttachTo = “[Event Click] = [Action InvokeExecute]”;
menu_item.Execute = () => Execute(menu_item);
_items.Add(menu_item);

But I can test tomorrow maybe. If your execute method is being called then there is something that is not retaining the value to the checkbox. Try creating a breakpoint at the end of your Execute method to evaluate the action item. If you have snoop, you could also use that to inspect the check box itself. Otherwise, I am sure someone has the answer, but prolly hasn’t noticed the post.

What is ribbon group icon and how I can use it?

@andreluizfc

Sorry for the long delay.

To make a checkbox, you need to do this:

  1. APCheckBoxTopApproach needs to be implemented as an ActionItem<bool>. So in your collections, you would also need to update them to use ActionItem<bool>.
  2. APCheckBoxTopApproach needs to be a MenuTools.CheckableMenuTool. That would then require you to override the Execute() method

    public override void Execute(bool isChecked)
    {//insert your code}

My friend, let me know if this helps you.

@ilkka look at the project attached in the original post. that shows you how to implement a ribbon group. the icon itself can come from the Icons folder in VC program files or your own, just make sure it is an SVG. you will also find an old beta tutorial on this forum thread on how to use the icon.

@zetsy

Thanks for the reply. I’ll test as soon as possible and let you know!