How-To: Enable/Disable ribbon button
Posted: Wed May 23, 2018 3:59 pm
You can initialize the ribbon button state to disabled adding "DefaultDisabled" to the style attribute of the Button element definition (in the CTD file).
To change the state, you will need to register the button handler. Include an event handler for the Query Status delegate.
When the ribbon control needs to display the button or a state change is detected, it will call your QueryStatus handler and you set the state.
Code: Select all
<Button id="RibbonButton1" kind="Button" largeImage="Resources\Gear_32x32.png"
smallImage="Resources\Gear_16x16.png" priority="10" text="Explode"
style="TextUnderneath DefaultDisabled"
toolTip="Click here to invoke RibbonButton1." />
Code: Select all
// RibbonButton1_Invoked called when button is pressed when enabled.
// RibbonButton1_QueryStatus is called when ribbon is about to display button and needs enable/disable state.
this.RegisterHandler(MyPackage.RibbonButton1, this.RibbonButton1_Invoked, this.RibbonButton1_QueryStatus);
Code: Select all
private void RibbonButton1_QueryStatus(object sender, QueryStatusEventArgs e)
{
e.Enabled = (true/false)
}