Enable/Disable ribbon button based on context

Add-in Express™ Support Service
That's what is more important than anything else

Enable/Disable ribbon button based on context
 
Burim Ratkoceri


Guest


Hi,

I am trying to find a way to change the enabled property of a custom ribbon control based on the context. For example I have a button that straighten lines in PowerPoint, and would like for it to be enabled only when a line or arrow is selected.

Thanks,
Burim Ratkoceri
Posted 12 May, 2016 03:05:03 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Burim,

You need to handle the PropertyChanging event of your ribbon button. Please have a look at the
https://www.add-in-express.com/docs/net-ribbon-components.php#properties-events chapter for more information.
Posted 12 May, 2016 04:57:08 Top
Burim Ratkoceri


Guest


Hi,

Thanks for the answer. I have already tried that but it doesn't fire when I for example select a line on the slide.

Thanks.
Posted 12 May, 2016 06:11:34 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Burim,

Sorry, my fault. You need to call the ADXRibbonButton.Invalidate() method so that PowerPoint retrieves all ribbon button properties anew. You can do this in the SlideSelectionChanged or/and WindowSelectionChange event handlers, for example:

private void adxPowerPointAppEvents1_SlideSelectionChanged(object sender, object hostObj)
{
    adxRibbonButton1.Invalidate();
}

private void adxPowerPointAppEvents1_WindowSelectionChange(object sender, object hostObj)
{
    adxRibbonButton1.Invalidate();
}

private void adxRibbonButton1_PropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
{
    // TODO
}
Posted 12 May, 2016 10:12:20 Top
Burim Ratkoceri


Guest


Hi Dmitry,

Thanks for the solution, it is working fine for me.
Posted 13 May, 2016 04:46:23 Top