StructuredDocumentTagStyle Property

Gets or sets the Style of the structured document tag.

Namespace:  Aspose.Words.Markup
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public Style Style { get; set; }

Property Value

Type: Style
Remarks
Only Character style or Paragraph style with linked character style can be set.
Examples
Shows how to work with styles for content control elements.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Get specific style from the document to apply it to an SDT
Style quoteStyle = doc.Styles[StyleIdentifier.Quote];
StructuredDocumentTag sdtPlainText = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
sdtPlainText.Style = quoteStyle;

StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline);
// Second method to apply specific style to an SDT control
sdtRichText.StyleName = "Quote";

// Insert content controls into the document
builder.InsertNode(sdtPlainText);
builder.InsertNode(sdtRichText);

MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, SaveFormat.Docx);

// We can get a collection of StructuredDocumentTags by looking for the document's child nodes of this NodeType
Assert.AreEqual(NodeType.StructuredDocumentTag, sdtPlainText.NodeType);

NodeCollection tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);

foreach (Node node in tags)
{
    StructuredDocumentTag sdt = (StructuredDocumentTag) node;
    // If style was not defined before, style should be "Default Paragraph Font"
    Assert.AreEqual(StyleIdentifier.Quote, sdt.Style.StyleIdentifier);
    Assert.AreEqual("Quote", sdt.StyleName);
}
See Also