简体   繁体   中英

Accessing another ribbon element in IRibbonExtensibility class

I have a project in which I'm using the Office.IRibbonExtensibility inheritance. The issue I'm having is that my project requires me to 'uncheck' a checkbox when a button is pressed on the ribbon. As far as I can tell, only your currently selected control is accessible in code through the Office.IRibbonControl property of the button press handler. So my question is, how do I access my checkbox element in the button click event in an XML based VSTO project?

Try this code

Ribbon.xml

<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
        <tabs>
            <tab idMso="TabAddIns">
              <group id="group1" label="group1">
                <button id ="btnTest" size="large" label="TestButton" onAction="btnTest_Click"/>
                <checkBox id ="chkTest" label="TestCheckbox" getPressed="chkTest_pressed" />
              </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

Ribbon.cs

private bool isChecked = false;
public void btnTest_Click(IRibbonControl ribbon)
{
    isChecked = true;
    this.ribbon.Invalidate();
}
public bool chkTest_pressed(IRibbonControl ribbon)
{
    return isChecked;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM