none
Slide Selection Change Event does not gets fired RRS feed

  • Question

  • Hi All...<o:p></o:p>

    I am developing PowerPoint add-in. It work fine on startup. But when user manually deselect the add-in from Developer tab-> COM Add-in dialogue box and close the dialogue box, Now again selecting  the add-in from Add-in dialogue box, Application events do not fire. I have written some code on  event, but not working as after add-in is re-enabled events are not fired.<o:p></o:p>

    I have created button on Ribbon which gets enabled/disabled depending upon the slide selected. This code is written on Application_SlideSelectionChanged event, But as event is not firing, the nothing happens. <o:p></o:p>

    I have added the SlideSelectionChanged event on ThisAddIn_Startup event. While debugging I have observed that Thisaddin_Startup is called when I re-enable the add-in but even if the event is added again it’s not working.<o:p></o:p>

    Can you please suggest how to re-bind the events or any alternative? <o:p></o:p>

    Thanks in advance!!!<o:p></o:p>

    Monday, May 19, 2014 10:03 AM

Answers

  • Hi Manish,

    I could reproduce the issue and here is what the issue that we are getting into:

    Until you unsubscribe from an event, the multicast delegate that underlies the event in the publishing object has a reference to the delegate that encapsulates the subscriber's event handler. As long as the publishing object holds that reference, garbage collection will not delete your subscriber object.


    Recommendation:

    Unsubscribe the event handler at Add-In Shutdown


     private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Globals.ThisAddIn.Application.SlideSelectionChanged += new PowerPoint.EApplication_SlideSelectionChangedEventHandler(Application_SlideSelectionChanged);
            }

            void Application_SlideSelectionChanged(PowerPoint.SlideRange SldRange)
            {
                System.Windows.Forms.MessageBox.Show("Selection Changed");
            }

            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
                Globals.ThisAddIn.Application.SlideSelectionChanged -= Application_SlideSelectionChanged;
            }

    Reference
    http://msdn.microsoft.com/en-us/library/ms366768.aspx


    Sangeeth,MSFT

    Thursday, May 22, 2014 1:18 AM

All replies

  • Hello Manish,

    What code do you use for subscribing to the events? Could you please be more specific?

    > I have created button on Ribbon which gets enabled/disabled depending upon the slide selected.

    The Ribbon UI is a static thing from its birth. The only possible dynamism is callbacks. You can read more about the UI in the following articles in MSDN:

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    Also you may find the Customize the Office user interface in Office 2010 article helpful.

    Monday, May 19, 2014 4:48 PM
  • Thanks Eugene for the reply!

    To be more specific, I am developing the PowerPoint Plug-in using Visual Studio 2010. The Project template used is PowerPoint 2010 Add-in. 

    I have added a Custom Ribbon with some buttons on it. For a specific button, I need it to be enabled/disabled based on the Current Selected Slide. For implementing the same, I have used, Application_SlideSelectionChanged(PowerPoint.SlideRange sldRange) event. This event is subscribed under Startup event of the ThisAddIn Class as; 

    private void ThisAddIn_Startup(object sender, System.EventArgs e) 

    {

    ...

    this.Application.SlideSelectionChanged += Application_SlideSelectionChanged;

    }

    For Refreshing the Ribbon UI, I have used Invalidate() method of Microsoft.Office.Core.IRibbonUI interface. The Invalidate method is also called under the  Application_SlideSelectionChanged(PowerPoint.SlideRange sldRange) event as ;

    void Application_SlideSelectionChanged(PowerPoint.SlideRange sldRange)

    {

    //Enable/Disable Code

    objRibbon.objRibbonUI.Invalidate();

    }

    The Issue is every thing works as expected until I manually disable and re-enable the Add-in from Developer->Com Add-ins. After re-enabling the Add-in, Whenever I change the Slide Application_SlideSelectionChanged(PowerPoint.SlideRange sldRange) does not gets fired.

    Tuesday, May 20, 2014 5:54 AM
  • Hi Manish

    Are you sure the event is not firing, or is it possible that the Ribbon invalidation is not taking place? Have you put any debugging code in the event to be sure of its firing?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, May 20, 2014 1:36 PM
    Moderator
  • Hi Manish,

    Thanks for your feedback.

    I'm facing the same issue as you mentioned.

    I create a simple VSTO project for testing, here is the code:

    private void ThisAddIn_Startup(object sender, System.EventArgs e) {

    Globals.ThisAddIn.Application.SlideSelectionChanged += Application_SlideSelectionChanged; } void Application_SlideSelectionChanged(PowerPoint.SlideRange SldRange) { MessageBox.Show("Selection changed"); }

    SlideSelectionChanged event will not be fired after I re-enable this add-in through Developer tab-> COM Add-in.

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, May 21, 2014 7:31 AM
    Moderator
  • Hi Manish,

    I could reproduce the issue and here is what the issue that we are getting into:

    Until you unsubscribe from an event, the multicast delegate that underlies the event in the publishing object has a reference to the delegate that encapsulates the subscriber's event handler. As long as the publishing object holds that reference, garbage collection will not delete your subscriber object.


    Recommendation:

    Unsubscribe the event handler at Add-In Shutdown


     private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Globals.ThisAddIn.Application.SlideSelectionChanged += new PowerPoint.EApplication_SlideSelectionChangedEventHandler(Application_SlideSelectionChanged);
            }

            void Application_SlideSelectionChanged(PowerPoint.SlideRange SldRange)
            {
                System.Windows.Forms.MessageBox.Show("Selection Changed");
            }

            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
                Globals.ThisAddIn.Application.SlideSelectionChanged -= Application_SlideSelectionChanged;
            }

    Reference
    http://msdn.microsoft.com/en-us/library/ms366768.aspx


    Sangeeth,MSFT

    Thursday, May 22, 2014 1:18 AM