none
Hello - Hiding a button in my Ribbon-menu, C# word 2007 RRS feed

  • Question

  • Hello

    I've created a Ribbon-menu, that inherits the Office.Core.IRibbonExtensibility... The menu itself is defined in a XML-file and now I am wondering on how do I reach those controls at runtime?

    The start of the XML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
      <commands>
        <command idMso="FileNew" onAction="ThisAddIn_FileNew"/>
        <command idMso="FilePrint" onAction="ThisAddIn_Print"/>
      </commands>
    
      <ribbon>
        <officeMenu>
          <menu idMso="FilePrintMenu">
            <button id="btnPrint" onAction="btnPrintMenu" label="Print" imageMso="FileInternetFax" insertBeforeMso="FilePrint"/>
          </menu>
        </officeMenu>
        
        <tabs>
          <tab idMso="TabAddIns"></tab>
          <tab id="Tab" label="Custom" keytip="alt">
            <group id="group1" label="Sett Inn">
              <button id="btnSignature" onAction="btnSignature_Click" keytip="F3" screentip="Hurtigtast: Ctrl + F3" label="Underskrift" showImage="false" />

    Now I am wondering on how I can reach the "btnSignature" at the "bottom" of the XML-file displayed above, from C#, within my AddIn.

    What I've tried? Oh, not that much actually, just looked all over the place and googled, and search this very forum (but every search on this forum gives me 75.000.000~ish results... And the results, first page, is always displaying channel 9-random-topics..., using IE 10...well, back to topic):

    Looked here without luck:

    Globals.ThisAddin.Ribbons...

    Office.Core.IRibbonUI ribbon [object autogenerated when adding a new item to the project of type Ribbon.Xml]

    ...

    Suggestions? :)


    • Edited by colaohye Tuesday, April 16, 2013 8:38 AM
    Monday, April 15, 2013 1:06 PM

Answers

All replies

  • You can't access a Ribbon directly at run-time - it wasn't designed to work like that.

    Instead, you have to define callback procedures for the Ribbon controls, which are called by the attributes in the Ribbon, such as onAction:

       <button id="btnSignature" onAction="btnSignature_Click"

    You don't show us or mention a Ribbon class in your VSTO project, but when you Add a Ribbon XML part to your VSTO solution it should be generated for you automatically. Did you work carefully through the MSDN documentation:
      http://msdn.microsoft.com/en-us/library/aa942866.aspx

    So, reading the subject line, you ask about hiding a control. For that, you need the attribute getVisible. You need a callback procedure for that which will return true/false.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 15, 2013 3:23 PM
    Moderator
  • Hi ,

    As Cidy said that you can access to ribbon at run time,  but you can define Callback with Ribbon XML, the below article is said that how to hide the ribbon control, I think these are helpful for you.

    Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon (Part 1 of 2)

    Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon (Part 2 of 2)


    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer.

    • Marked as answer by colaohye Tuesday, April 16, 2013 10:23 AM
    Tuesday, April 16, 2013 5:57 AM
  • Cindy, " Add a Ribbon XML part to your VSTO solution it should be generated for you automatically", yes it has been added automatically. "I've created a Ribbon-menu, that inherits the Office.Core.IRibbonExtensibility", well, "I've", could and should have been "It was autogenerated"...

    Anyways...

    Learning hard: Part 1 of 2 did it, or at least gave an example... So on the events "AddIn_NewDocument" and "AddIn_OnOpenDocument" I am now displaying various buttons in my menu based on custom properties and which template has been opened/newly created...

    Tuesday, April 16, 2013 10:23 AM