RibbonButton like the Insert dropdown of buttons

RibbonButton like the Insert dropdown of buttons

Anonymous
Not applicable
658 Views
3 Replies
Message 1 of 4

RibbonButton like the Insert dropdown of buttons

Anonymous
Not applicable

I am trying to make a dropdown of buttons like the Insert button. Does anyone know type of button that is?

0 Likes
Accepted solutions (2)
659 Views
3 Replies
Replies (3)
Message 2 of 4

gleeuwdrent
Advocate
Advocate
Accepted solution

You can use this as extension method (and your own method to load your icon):

public static RibbonMenuButton AddMenuButton(this RibbonRowPanel rowPanel, string buttonId, string buttonText, string iconName)
{
	RibbonMenuButton menuButton = new RibbonMenuButton();
	menuButton.Text = buttonText;
	menuButton.Orientation = System.Windows.Controls.Orientation.Horizontal;
	menuButton.Size = RibbonItemSize.Standard;
	menuButton.ShowText = true;
	menuButton.LargeImage = LoadImage(iconName, 32, 32);
	menuButton.Image = LoadImage(iconName, 16, 16);
	menuButton.ShowImage = true;
	menuButton.ListButtonStyle = Autodesk.Private.Windows.RibbonListButtonStyle.MenuButton;
	menuButton.Id = buttonId;
	rowPanel.Items.Add(menuButton);
	rowPanel.Items.Add(new RibbonRowBreak());
	return menuButton;
}

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

How do I add items to the menu?

0 Likes
Message 4 of 4

gleeuwdrent
Advocate
Advocate
Accepted solution

I use this extension:

 

public static void AddButtonToDropDown(this RibbonMenuButton menuButton, string buttonId, string buttonText, string description, string iconName, string command)
{
	RibbonMenuItem button = new RibbonMenuItem();
	button.Text = buttonText;
	button.ShowText = true;
	button.ShowImage = true;
	button.LargeImage = LoadImage(iconName,, 32, 32);
	button.Image = LoadImage(iconName, 16, 16);
	button.Id = buttonId;
	button.CommandParameter = command;
	button.Description = description;
	button.CommandHandler = new AdskCommandHandler();
	menuButton.Items.Add(button);
}

 

 

With this CommandHandler:

 

public class AdskCommandHandler : System.Windows.Input.ICommand
{
	public bool CanExecute(object parameter)
	{
		return true;
	}
	public event EventHandler CanExecuteChanged;
	public void Execute(object parameter)
	{
		var ribbonItem = parameter as RibbonCommandItem;
		if (ribbonItem != null)
		{
			Autodesk.AutoCAD.ApplicationServices.Document doc = AcAp.DocumentManager.MdiActiveDocument;
			//Make sure the command text either ends with ";", or a " "
			string cmdText = ((string)ribbonItem.CommandParameter).Trim();
			if (!cmdText.EndsWith(";")) cmdText = cmdText + " ";
			doc.SendStringToExecute(cmdText, true, false, true);
		}
	}
}

 

0 Likes