Aspose::Words::Markup::StructuredDocumentTag::set_Style method

StructuredDocumentTag::set_Style method

Sets the Style of the structured document tag.

void Aspose::Words::Markup::StructuredDocumentTag::set_Style(const System::SharedPtr<Aspose::Words::Style> & value)

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.

auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);

// Below are two ways to apply a style from the document to a structured document tag.
// 1 -  Apply a style object from the document's style collection:
System::SharedPtr<Aspose::Words::Style> quoteStyle = doc->get_Styles()->idx_get(StyleIdentifier::Quote);
auto sdtPlainText = System::MakeObject<Aspose::Words::Markup::StructuredDocumentTag>(doc, SdtType::PlainText, MarkupLevel::Inline);
sdtPlainText->set_Style(quoteStyle);

// 2 -  Reference a style in the document by name:
auto sdtRichText = System::MakeObject<Aspose::Words::Markup::StructuredDocumentTag>(doc, SdtType::RichText, MarkupLevel::Inline);
sdtRichText->set_StyleName(u"Quote");

builder->InsertNode(sdtPlainText);
builder->InsertNode(sdtRichText);

ASSERT_EQ(sdtPlainText->get_NodeType(), NodeType::StructuredDocumentTag);

System::SharedPtr<Aspose::Words::NodeCollection> tags = doc->GetChildNodes(NodeType::StructuredDocumentTag, true);

for (auto&& node : System::IterateOver(tags))
{
    auto sdt = System::ExplicitCast<Aspose::Words::Markup::StructuredDocumentTag>(node);

    std::cout << sdt->get_WordOpenXMLMinimal() << std::endl;

    ASSERT_EQ(sdt->get_Style()->get_StyleIdentifier(), StyleIdentifier::Quote);
    ASSERT_EQ(sdt->get_StyleName(), u"Quote");
}

See Also