I would like to create a ToolBar item corresponding to a menu item. Please advice me how to do this.

asked 12 Jan '11, 20:02

jinij's gravatar image

accept rate: 0%

Hello! First, I'm assuming you've read How do I make my add-in add a menu item to the main menu?

Then you need to make a tool bar (you can have many toolbars and each toolbar can have toolbar buttons in it). Here's how to make a simple toolbar:

[Export(SoapBox.Core.ExtensionPoints.Workbench.ToolBars, typeof(IToolBar))]
public class SomeToolBar : AbstractToolBar, IPartImportsSatisfiedNotification
    public SomeToolBar()
        Name = "My ToolBar Name";
        VisibleCondition = new ConcreteCondition(true);

    private IExtensionService extensionService { get; set; }

    [ImportMany("My ToolBar Contract Name", typeof(IToolBarItem))]
    private IEnumerable<IToolBarItem> items { get; set; }

    public void OnImportsSatisfied()
        Items = extensionService.Sort(items);

Now to add a button to it, you'd do this:

[Export("My ToolBar Contract Name", typeof(IToolBarItem))]
public class MyToolBarButton : AbstractToolBarButton
    public MyToolBarButton()
        ID = "MyButtonId";
        ToolTip = "Click Me!";

    [Import("Some Other Component In Your Solution", typeof(IYourService))]
    private IYourService yourService { get; set; }

    protected override void Run()

The contents of the Run method in the last little bit there should be identical to the contents of the Run method in your Menu Item. That is, you need both a menu item defined and a tool bar and a tool bar button defined, but the menu item and button should both delegate to some business logic elsewhere in your application.


answered 12 Jan '11, 20:33

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦
accept rate: 50%

Thank you very much. It worked! Cheers!

(13 Jan '11, 08:40) jinij
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 12 Jan '11, 20:02

Seen: 2,057 times

Last updated: 17 Jan '11, 06:49

powered by OSQA