Collapse Content Control in Word Document

Hello. I have a sort of templator in application. And I use Content Controls as “placeholders” for that reason. I like them… works perfectly.

And usually when there is no value for placeholder I can just set Font.Hidden to true. And it stil takes a place for it. And usually it’s not a problem.
But there are a cases when I need to “collapse” Content Control(so it will not take horizontal and vertical space when there is no value for it). And for Horizontal - I can set text to empty string. But what can I do to make so that it will not take vertical place?

Tecnically I need a sort of collapse feature for Content Control? Any ideas? it can be sort of workaround if there is no clean way of doing that.

@vabrutski I am afraid there is no option to “collapse” SDT since there is no such feature in MS Word document format. However setting it as hidden should fully hide SDT if “Show/Hide” option is disabled in MS Word.

Document doc = new Document(@"C:\Temp\in.docx");
StructuredDocumentTag sdt = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
foreach (Node child in sdt.GetChildNodes(NodeType.Any, true))
{
    if (child.NodeType == NodeType.Paragraph)
        ((Paragraph)child).ParagraphBreakFont.Hidden = true;
    if (child is Inline)
        ((Inline)child).Font.Hidden = true;
}
doc.Save(@"C:\Temp\out.docx");

Thank you Alexey

Just to exact. Your code example will hide the content but not collapse? Am I correct?

@vabrutski Yes, you are right, it will hide SDT if “Show/Hide” option is disabled in MS Word.