none
Multiple Project with same ribbon RRS feed

  • Question

  • I am developing a project in VSTO 2010 and just came to the following situation.

    I have a ribbon function which opens a WPF form to take user input in these templates. I have few templates which share this function . At the moment I have to add new ribbon to each template and duplicate the code. As only few of my templates share this function, I can not put this ribbon on application level.

    I tried creating a separate project for Ribbon but thing is that you can not call a custom public method of Global.ThisDocument from this ribbon project.

    ThisDocument.cs has a public method called TakeUserInput() which opens WPF form for user input. If Ribbon.cs is inside the same project, I can call it via Global.ThisDocument.TakeUserInput()

    Current situation:

    ThisDocument Project 1
    -ThisDocument.cs 
    -Ribbon 

    ThisDocument Project 2
    -ThisDocument.cs 
    -Ribbon
    .......
    ThisDocument Project N
    -ThisDocument.cs 
    -Ribbon


    Preferred situation:

    ThisDocument Project 1
    -ThisDocument.cs 
    .......

    ThisDocument Project N
    -ThisDocument.cs 

    Ribbon Project (ThisDocument object)
    -object.TakeUserInput()


    Is there a way to achieve the above situation? This way I can avoid code duplication. 
    What I have already tried
     -Library Project for Ribbon and an Interface for Project types


    Thanks in advance!
    Regards

    Thursday, April 11, 2013 9:16 AM

Answers

  • for application level add-in you could override createribbonextensibilityobject to return component from another, shared assembly. However i do not know if this would Work with document level customizations. Try searching through API and see if there is some override that looks promising. Otherwise you are out of luck because vsto runtime uses reflection to determine what services add-in provides and it scans only main add-in dll, so the best de-duplication that you could achieve this way is having just stubs for ribbon in each main assembly that delegate all the Work to shared assembly.

    Thursday, April 11, 2013 10:18 AM