What's the "proper" way to retrieve a reference to a ribbon object?

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2011-01-06T01:17:55Z Indexed on 2011/01/08 4:53 UTC
Read the original article Hit count: 190

Filed under:
|
|
|

For a VSTO workbook project, is there a best practice for retrieving a reference to the Ribbon object from the ThisWorkbook class?

Here's what I'm doing: In my Ribbon class, I created a public method called InvalidateControl(string controlID). I need to call that method from the ThisWorkbook class based on when a certain workbook level event fires. But the only way I can see to "get" a reference to that Ribbon object is to do this...

    // This is all in the ThisWorkbook class
    Ribbon ribbon;
    protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
        this.ribbon = new Ribbon();
        return this.ribbon;
    }

...which seems a little smelly. I mean, I have to override CreateRibbonExtensibilityObject() regardless; all I'm doing beyond that is maintaining a local reference to the ribbon so I can call methods against it. But it doesn't feel right. Is there another, better way to get that reference in the ThisWorkbook class? Or is this pretty acceptable?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about vsto