none
ContentControl SetPlaceholderText and Design Mode

    Question

  • I'm working on a managed code, Word 2007 Add-In using Visual Studio 2005 with VSTO and VSTO SE. I am creating Text Content Controls from the Add-In. However, if I try to specify placeholder text for the content control, via ContentControl.SetPlaceholderText(), the placeholder text is not displayed in the content control in the document. I checked that the ContentControl.PlaceholderText is indeed set with the Value I provided; it is just not displayed within the content control in the document. Also, when the text content control is created in this way (specifying placeholder text), the following error message is displayed when I toggle out of "Design Mode" (Word Menu > Developer Tab > Controls Group > Design Mode button):

    "Word cannot turn off design mode because placeholder text in a content control contains invalid items. Placeholder text cannot contain Items such as floating objects, revision marks, or content controls, Remove these items from the placeholder text and try again."

    If I do not set the placeholder text explicitly for the content control, the default placeholder text, "Click here to enter text." is shown and the "Design Mode" error does not occur. Below I have included code samples that demonstrate the error case described and the working case. Is this a valid way to use ContentControl.SetPlaceholderText? Has anyone else encountered this problem and is there a workaround? Any help would be appreciated.

     

    Thanks,

    Harry Sauers

     

    Code Snippet

    // Placeholder text is not displayed and

    // exiting Design Mode causes error

    private void CreateContentControl()

    {

        Object defaultRange = System.Type.Missing;

        ContentControl contentCtrl = this.Application.ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlText, ref defaultRange);

        contentCtrl.Title = "My Title";

        contentCtrl.Tag = "My Tag";

        string placeHolderText = "My placeholder text.";

        contentCtrl.SetPlaceholderText(null, null, placeHolderText);

        // "My placeholder text." is not displayed in the content control

    }

     

    // Works

    private void CreateContentControl2()

    {

        Object defaultRange = System.Type.Missing;

        ContentControl contentCtrl = this.Application.ActiveDocument.ContentControls.Add(WdContentControlType.wdContentControlText, ref defaultRange);

        contentCtrl.Title = "My Title";

        contentCtrl.Tag = "My Tag";

        // Default placeholder text is used and

        // displayed: "Click here to enter text."

    }

     

     

     

    Friday, June 08, 2007 9:02 PM

Answers

  • Hi Harry

     

    I think the problem has to do with the fact that you're in Design mode. The behavior doesn't occur if Design mode isn't active.

     

    Perhaps this is because the user has no access to the functionality for setting placeholder text, and DesignMode is purely an end-user functionality. Try toggling Design Mode and see if that helps.

     

                  object defaultRange = System.Type.Missing;
                    Word.Application app = Globals.ThisAddIn.Application;
                    Word.Document doc = app.ActiveDocument;
                    Word.ContentControl cc = doc.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref defaultRange);
                    cc.Title = "Test1";
                    cc.Tag = "Test1";
                    string placeholder = "Test new placeholder";
                     bool toggleDesignMode = doc.FormsDesign;
                    if (toggleDesignMode) doc.ToggleFormsDesign();
                    cc.SetPlaceholderText(null, null, placeholder);
                    if (toggleDesignMode) doc.ToggleFormsDesign();

    Saturday, June 09, 2007 7:58 AM

All replies

  • Hi Harry

     

    I think the problem has to do with the fact that you're in Design mode. The behavior doesn't occur if Design mode isn't active.

     

    Perhaps this is because the user has no access to the functionality for setting placeholder text, and DesignMode is purely an end-user functionality. Try toggling Design Mode and see if that helps.

     

                  object defaultRange = System.Type.Missing;
                    Word.Application app = Globals.ThisAddIn.Application;
                    Word.Document doc = app.ActiveDocument;
                    Word.ContentControl cc = doc.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref defaultRange);
                    cc.Title = "Test1";
                    cc.Tag = "Test1";
                    string placeholder = "Test new placeholder";
                     bool toggleDesignMode = doc.FormsDesign;
                    if (toggleDesignMode) doc.ToggleFormsDesign();
                    cc.SetPlaceholderText(null, null, placeholder);
                    if (toggleDesignMode) doc.ToggleFormsDesign();

    Saturday, June 09, 2007 7:58 AM
  • Thanks Cindy.

     

    That was it. If I ensure that I'm out of design mode when creating the placeholder text, it works just fine. I put Design Mode back into its original state afterwards and there are no errors; the placeholder text is displayed and I can manually toggle design mode at will without any error messages. I appreciate your help.

     

    Thanks,

    Harry

    Monday, June 11, 2007 1:01 PM
  • Harry,

    Sorry to post here, but trying to find out if you even got an answer to the following:
    From tech-archive.net, "Harry Sauers" wrote:

    When using (Office 2007 SP1) Word 2007 content controls, specifically nested
    group content controls, I have noticed that usually the content controls have
    triangles/arrows within the visible tags of the control as shown in Design
    Mode (Word Developer tab > Design Mode toggled on). Sometimes I have noticed
    these controls do not show these triangles/arrows within their beginning and
    ending tags. I have noticed these arrows disappearing from nested content
    controls (content controls contained within a group content control) when
    whitespace (space, newline, etc) is added or removed from the area of the
    document near the contained content control and within the same parent group
    content control.

    When the group content control does not have these arrows, I have noticed
    that it behaves differently than when it does have these arrows. For example,
    I have noticed that once these arrows are no longer visible on a nested group
    content control that a new paragraph (ENTER/hard return) cannot be inserted
    within the group content control.

    1) What is the significance or purpose of the triangles/arrows within the
    visible tags of the Word 2007 content controls when design mode is enabled?
    2) Why do these arrows disappear in some cases, changing the behavior of the
    editor within the control?
    3) What can be done to avoid this group content control state that does not
    allow new lines (hard returns) to be entered?

    Thanks,
    Harry Sauers


    Steps to reproduce this behavior:
    1) In Word 2007, enable the Developer tab
    2) Developer Tab > Insert a plain text content control (second “Aa” icon in
    the Controls button group).
    3) Toggle Design Mode on
    4) Select the entire plain text content control that was just created,
    including its tags.
    5) Group the selection (create a group content control around the selection).
    6) Select the entire group content control that was just created, including
    its tags.
    7) Group the selection (create another group content control around the
    selection).
    Note the arrows decorating the beginning and ending tags of all of the
    content controls.
    8) Place cursor within the outer group content control, but outside of the
    inner group content control’s tags. Keyboard arrow keys may be necessary for
    this.
    9) Enter a space in this area between the 2 group content controls’ closing
    tags.
    * The arrows of the inner group content control and its contained plain text
    content control disappear.
    * Hard returns (ENTER) can no longer be entered within the inner group
    content control.

    I can report that an additional weird behaviour of the content controls with shaded tags is that you cannot add a new content control based on selecting the para mark at the end of the para.
    Monday, June 08, 2009 2:27 AM