none
ContentControlOnExit is not fired if it is mapped to xml RRS feed

  • Question

  • I had a document with some contentcontrols. In my VSTO-Addin i use the events:
    Private Sub ActiveDocument_ContentControlOnExit(ContentControl As ContentControl, ByRef Cancel As Boolean) Handles ActiveDocument.ContentControlOnExit
    Private Sub ActiveDocument_ContentControlOnEnter(ContentControl As ContentControl) Handles ActiveDocument.ContentControlOnEnter

    If i have no XML Mapping on the ContentControls all events works fine.
    But if i have XML Mapped ContentControls and changed the content and leave the Control the Event "ContentControlOnExit" is never fired.

    If i change from one Mapped ContentControl to an other ContentControl without changing text the Events are fired. But if i have changed the Text and go to an other ContentControl neither of the two is fired.

    Is this a Bug or a feature? What can i do to get these Events?

    If i use the Event "ContentControlBeforeStoreUpdate" i have no full access to the Document. An
    Application.ScreenUpdating = False
    give the error: "This object model command is not available while in the current event"

    What can i do?



    • Edited by Bismosa Thursday, November 26, 2015 12:34 PM
    Thursday, November 26, 2015 12:32 PM

Answers

  • Hi Bismosa,

    >>But if i have XML Mapped ContentControls and changed the content and leave the Control the Event "ContentControlOnExit" is never fired.<<

    I am trying to reproduce this issue in Word 2013, however failed. Here is the test steps:

    1. Click the button to start the event:

      private void btnStartEvent_Click(object sender, RibbonControlEventArgs e)
            {
                Globals.ThisAddIn.Application.ActiveDocument.ContentControlOnEnter += ActiveDocument_ContentControlOnEnter;
                Globals.ThisAddIn.Application.ActiveDocument.ContentControlOnExit += ActiveDocument_ContentControlOnExit;
            }

    2. Show the XML mapping pane and insert content control from the pane like figure below:

    3. Change the content in the content control and leave it

    >>If i use the Event "ContentControlBeforeStoreUpdate" i have no full access to the Document. An
    Application.ScreenUpdating = False<<

     This event would updates data in a custom XML part that is bound to the content control. And yes, there is some object is not available in this event.

    I suggest that you create an new VSTO solution as the steps above and the issue still could be reproduced, you can try to update or repair the Office to see whether it is helpful.

    Regards & Fei


    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.

    • Marked as answer by Bismosa Friday, November 27, 2015 8:47 AM
    Friday, November 27, 2015 6:18 AM
    Moderator

All replies

  • Hi Bismosa,

    >>But if i have XML Mapped ContentControls and changed the content and leave the Control the Event "ContentControlOnExit" is never fired.<<

    I am trying to reproduce this issue in Word 2013, however failed. Here is the test steps:

    1. Click the button to start the event:

      private void btnStartEvent_Click(object sender, RibbonControlEventArgs e)
            {
                Globals.ThisAddIn.Application.ActiveDocument.ContentControlOnEnter += ActiveDocument_ContentControlOnEnter;
                Globals.ThisAddIn.Application.ActiveDocument.ContentControlOnExit += ActiveDocument_ContentControlOnExit;
            }

    2. Show the XML mapping pane and insert content control from the pane like figure below:

    3. Change the content in the content control and leave it

    >>If i use the Event "ContentControlBeforeStoreUpdate" i have no full access to the Document. An
    Application.ScreenUpdating = False<<

     This event would updates data in a custom XML part that is bound to the content control. And yes, there is some object is not available in this event.

    I suggest that you create an new VSTO solution as the steps above and the issue still could be reproduced, you can try to update or repair the Office to see whether it is helpful.

    Regards & Fei


    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.

    • Marked as answer by Bismosa Friday, November 27, 2015 8:47 AM
    Friday, November 27, 2015 6:18 AM
    Moderator
  • Hello Fei,

    many thanks for the try. I have only Office 2010 to test. I have used the ContentControlToolkit to map the ContentControls. I have made a test with VBA and without my AddIn. Than it worked.

    Now i have found my error. I have a event "Application.WindowSelectionChange" in my Ribbon Control. In this event i get
    Sel.Information(WdInformation.wdActiveEndAdjustedPageNumber)
    if i try to get this if the cursor is in the ContentControl (and the Content is changed) the events are missed.

    My Workaround for this issue is to test for contentcontrols in the Application.WindowSelectionChange:
                 Try
                    If Sel.Range.Sentences(1).ContentControls.Count > 0 Then
                        Exit Sub
                    End If
                Catch ex As Exception
                    Exit Sub
                End Try

    and now it works fine.

    Thank you for your Help!

    Regards Bismosa

    Friday, November 27, 2015 8:47 AM