I’m programmatically creating a content control and want to put my own text in the Placeholder. I’ve tried numerous things, including first removing the default text, but I cannot get it to display as the faint text prompt and instead it just shows as regular text…
public static void TestCreateContentControl(string ccTitle, string ccTag, string ccPlaceholder, bool ssPreventEditing, bool ssPreventDeletion, string ssFilenameAndPath)
{
Document doc = new Document(ssFilenameAndPath);
Paragraph para = new Paragraph(doc);
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
if (ssPreventEditing == true)
{
// Prevent users from editing the contents of the Content Control
sdtRichText.LockContents = true;
}
else
{
// Allows users to edit the contents of the Content Control
sdtRichText.LockContents = false;
}
if (ssPreventDeletion == true)
{
// Prevent users from deleting the Content Control
sdtRichText.LockContentControl = true;
}
else
{
// Allows users to delete the Content Control
sdtRichText.LockContentControl = false;
}
sdtRichText.Tag = ccTag;
sdtRichText.Title = ccTitle;
sdtRichText.ChildNodes.Add(para);
doc.FirstSection.Body.AppendChild(sdtRichText);
//// Remove default Placeholder (i.e. text prompt)
//Paragraph target = (Paragraph)sdtRichText.LastChild;
//sdtRichText.RemoveAllChildren();
// Set the text value
Run run = new Run(doc);
run.Text = ccPlaceholder;
run.Font.Name = "Arial";
run.Font.Size = 10;
para.Runs.Add(run);
//GlossaryDocument glossaryDoc = doc.GlossaryDocument;
//Aspose.Words.BuildingBlocks.BuildingBlock substituteBlock = new Aspose.Words.BuildingBlocks.BuildingBlock(glossaryDoc);
//substituteBlock.Name = "MyTestPlaceholder";
//substituteBlock.AppendChild(new Section(glossaryDoc));
//substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));
//substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text.");
//glossaryDoc.AppendChild(substituteBlock);
// Convert the text value to a Placeholder
sdtRichText.IsShowingPlaceholderText = true;
doc.Save(ssFilenameAndPath);
}