Add-In menu items

Sep 10, 2008 at 9:01 AM
Hi all,

I have created an add-in and a host, and all are working fine (currently, I have developed it "by hand", but I want to use the Pipeline Generator Tool ASAP). Now, I want to allow every add-in to create a list of MenuItems. This is simply a collection of MenuItemAddInView (and HostView, and Contract) that include a header, icon and a delegate (RoutedEventHandler) that defines the method (inside the add-in) that needs to be executed.

I have created adapters for the MenuItem and the MenuItemCollection, but I get the following exception (translated):

Type MyProduct.AddIn.Test.TestAddIn in assembly MyProduct.AddIn.Test is not defined as serializable.

What is the best way to invoke a delegate through the add-ins and the adapters?

Thanks in advance!
Sep 11, 2008 at 9:02 PM
Hi Tischnoetentoet,

You can look at the event sample for a pattern to implement events with:

It should be straighforward to use a similar idea for delegates. Something like the following contract should work:

    public interface ISomethingHappenedEventHandler : IContract
        void Handler(ISomethingHappenedEventArgs args);

    public interface ISomethingHappenedEventArgs : IContract
        string Data

The EventArgs can be implemented on the host side, and the EventHandler can be implemented by the add-in. Then you should be able to create a SomethingHappenedEventHandler object on the add-in side, pass it to the host and have the host call the Handler() method on it whenever the menu item is clicked.


Sep 11, 2008 at 9:10 PM
Yes, I found the example, it was really helpful to me!

Thank you for your answer!