SdtListItemCollection
Namespace:
Aspose.Words
We found 5 examples in language CSharp for this search.
You will see 25 fragments of code.
Other methods
Other methods
Project:PersonalSpire
File:SdtListItemCollection.cs
Examples:1
internal SdtListItemCollection method_0()
{
SdtListItemCollection items = (SdtListItemCollection) base.MemberwiseClone();
items.list_0 = new List<SdtListItem>(this.list_0.Count);
for (int i = 0; i < this.list_0.Count; i++)
{
items.Add(this[i].method_0());
}
return items;
}
Project:Aspose.Words-for-.NET
File:ExStructuredDocumentTag.cs
Examples:6
[Test]
public void RepeatingSection()
{
//ExStart
//ExFor:StructuredDocumentTag.SdtType
//ExSummary:Shows how to get the type of a structured document tag.
Document doc = new Document(MyDir + "Structured document tags.docx");
List<StructuredDocumentTag> sdTags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true).OfType<StructuredDocumentTag>().ToList();
Assert.AreEqual(SdtType.RepeatingSection, sdTags[0].SdtType);
Assert.AreEqual(SdtType.RepeatingSectionItem, sdTags[1].SdtType);
Assert.AreEqual(SdtType.RichText, sdTags[2].SdtType);
//ExEnd
}
[Test]
public void ApplyStyle()
{
//ExStart
//ExFor:StructuredDocumentTag
//ExFor:StructuredDocumentTag.NodeType
//ExFor:StructuredDocumentTag.Style
//ExFor:StructuredDocumentTag.StyleName
//ExFor:MarkupLevel
//ExFor:SdtType
//ExSummary:Shows how to work with styles for content control elements.
Document doc = new Document();
DocumentBuilder builder = new 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:
Style quoteStyle = doc.Styles[StyleIdentifier.Quote];
StructuredDocumentTag sdtPlainText = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
sdtPlainText.Style = quoteStyle;
// 2 - Reference a style in the document by name:
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline);
sdtRichText.StyleName = "Quote";
builder.InsertNode(sdtPlainText);
builder.InsertNode(sdtRichText);
Assert.AreEqual(NodeType.StructuredDocumentTag, sdtPlainText.NodeType);
NodeCollection tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (Node node in tags)
{
StructuredDocumentTag sdt = (StructuredDocumentTag)node;
Assert.AreEqual(StyleIdentifier.Quote, sdt.Style.StyleIdentifier);
Assert.AreEqual("Quote", sdt.StyleName);
}
//ExEnd
}
[Test]
public void CheckBox()
{
//ExStart
//ExFor:StructuredDocumentTag.#ctor(DocumentBase, SdtType, MarkupLevel)
//ExFor:StructuredDocumentTag.Checked
//ExSummary:Show how to create a structured document tag in the form of a check box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
StructuredDocumentTag sdtCheckBox = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
sdtCheckBox.Checked = true;
builder.InsertNode(sdtCheckBox);
doc.Save(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
StructuredDocumentTag[] sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true).OfType<StructuredDocumentTag>().ToArray();
Assert.AreEqual(true, sdts[0].Checked);
Assert.That(sdts[0].XmlMapping.StoreItemId, Is.Empty);
}
#if NET462 || NETCOREAPP2_1 || JAVA // because of a Xamarin bug with CultureInfo (https://xamarin.github.io/bugzilla-archives/59/59077/bug.html)
[Test, Category("SkipMono")]
public void Date()
{
//ExStart
//ExFor:StructuredDocumentTag.CalendarType
//ExFor:StructuredDocumentTag.DateDisplayFormat
//ExFor:StructuredDocumentTag.DateDisplayLocale
//ExFor:StructuredDocumentTag.DateStorageFormat
//ExFor:StructuredDocumentTag.FullDate
//ExSummary:Shows how to prompt the user to enter a date with a structured document tag.
Document doc = new Document();
// Insert a structured document tag that prompts the user to enter a date.
// In Microsoft Word, this element is known as a "Date picker content control".
// When we click on the arrow on the right end of this tag in Microsoft Word,
// we will see a pop up in the form of a clickable calendar.
// We can use that popup to select a date that the tag will display.
StructuredDocumentTag sdtDate = new StructuredDocumentTag(doc, SdtType.Date, MarkupLevel.Inline);
// Display the date, according to the Saudi Arabian Arabic locale.
sdtDate.DateDisplayLocale = CultureInfo.GetCultureInfo("ar-SA").LCID;
// Set the format with which to display the date.
sdtDate.DateDisplayFormat = "dd MMMM, yyyy";
sdtDate.DateStorageFormat = SdtDateStorageFormat.DateTime;
// Display the date according to the Hijri calendar.
sdtDate.CalendarType = SdtCalendarType.Hijri;
// Before the user chooses a date in Microsoft Word, the tag will display the text "Click here to enter a date.".
// According to the tag's calendar, set the "FullDate" property to get the tag to display a default date.
sdtDate.FullDate = new DateTime(1440, 10, 20);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(sdtDate);
doc.Save(ArtifactsDir + "StructuredDocumentTag.Date.docx");
//ExEnd
}
#endif
[Test]
public void PlainText()
{
//ExStart
//ExFor:StructuredDocumentTag.Color
//ExFor:StructuredDocumentTag.ContentsFont
//ExFor:StructuredDocumentTag.EndCharacterFont
//ExFor:StructuredDocumentTag.Id
//ExFor:StructuredDocumentTag.Level
//ExFor:StructuredDocumentTag.Multiline
//ExFor:StructuredDocumentTag.Tag
//ExFor:StructuredDocumentTag.Title
//ExFor:StructuredDocumentTag.RemoveSelfOnly
//ExSummary:Shows how to create a structured document tag in a plain text box and modify its appearance.
Document doc = new Document();
// Create a structured document tag that will contain plain text.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the title and color of the frame that appears when you mouse over the structured document tag in Microsoft Word.
tag.Title = "My plain text";
tag.Color = Color.Magenta;
// Set a tag for this structured document tag, which is obtainable
// as an XML element named "tag", with the string below in its "@val" attribute.
tag.Tag = "MyPlainTextSDT";
// Every structured document tag has a random unique ID.
Assert.That(tag.Id, Is.Positive);
// Set the font for the text inside the structured document tag.
tag.ContentsFont.Name = "Arial";
// Set the font for the text at the end of the structured document tag.
// Any text that we type in the document body after moving out of the tag with arrow keys will use this font.
tag.EndCharacterFont.Name = "Arial Black";
// By default, this is false and pressing enter while inside a structured document tag does nothing.
// When set to true, our structured document tag can have multiple lines.
// Set the "Multiline" property to "false" to only allow the contents
// of this structured document tag to span a single line.
// Set the "Multiline" property to "true" to allow the tag to contain multiple lines of content.
tag.Multiline = true;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
// Insert a clone of our structured document tag in a new paragraph.
StructuredDocumentTag tagClone = (StructuredDocumentTag)tag.Clone(true);
builder.InsertParagraph();
builder.InsertNode(tagClone);
// Use the "RemoveSelfOnly" method to remove a structured document tag, while keeping its contents in the document.
tagClone.RemoveSelfOnly();
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
Assert.AreEqual("My plain text", tag.Title);
Assert.AreEqual(Color.Magenta.ToArgb(), tag.Color.ToArgb());
Assert.AreEqual("MyPlainTextSDT", tag.Tag);
Assert.That(tag.Id, Is.Positive);
Assert.AreEqual("Arial", tag.ContentsFont.Name);
Assert.AreEqual("Arial Black", tag.EndCharacterFont.Name);
Assert.True(tag.Multiline);
}
[TestCase(false)]
[TestCase(true)]
public void IsTemporary(bool isTemporary)
{
//ExStart
//ExFor:StructuredDocumentTag.IsTemporary
//ExSummary:Shows how to make single-use controls.
Document doc = new Document();
// Insert a plain text structured document tag,
// which will act as a plain text form that the user may enter text into.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the "IsTemporary" property to "true" to make the structured document tag disappear and
// assimilate its contents into the document after the user edits it once in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to edit the contents
// of the structured document tag any number of times.
tag.IsTemporary = isTemporary;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Please enter text: ");
builder.InsertNode(tag);
// Insert another structured document tag in the form of a check box and set its default state to "checked".
tag = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
tag.Checked = true;
// Set the "IsTemporary" property to "true" to make the check box become a symbol
// once the user clicks on it in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to click on the check box any number of times.
tag.IsTemporary = isTemporary;
builder.Write("\nPlease click the check box: ");
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
Assert.AreEqual(2,
doc.GetChildNodes(NodeType.StructuredDocumentTag, true).Count(sdt => ((StructuredDocumentTag)sdt).IsTemporary == isTemporary));
}
[TestCase(false)]
[TestCase(true)]
public void PlaceholderBuildingBlock(bool isShowingPlaceholderText)
{
//ExStart
//ExFor:StructuredDocumentTag.IsShowingPlaceholderText
//ExFor:StructuredDocumentTag.Placeholder
//ExFor:StructuredDocumentTag.PlaceholderName
//ExSummary:Shows how to use a building block's contents as a custom placeholder text for a structured document tag.
Document doc = new Document();
// Insert a plain text structured document tag of the "PlainText" type, which will function as a text box.
// The contents that it will display by default are a "Click here to enter text." prompt.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// We can get the tag to display the contents of a building block instead of the default text.
// First, add a building block with contents to the glossary document.
GlossaryDocument glossaryDoc = doc.GlossaryDocument;
BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc);
substituteBlock.Name = "Custom Placeholder";
substituteBlock.AppendChild(new Section(glossaryDoc));
substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));
substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text.");
glossaryDoc.AppendChild(substituteBlock);
// Then, use the structured document tag's "PlaceholderName" property to reference that building block by name.
tag.PlaceholderName = "Custom Placeholder";
// If "PlaceholderName" refers to an existing block in the parent document's glossary document,
// we will be able to verify the building block via the "Placeholder" property.
Assert.AreEqual(substituteBlock, tag.Placeholder);
// Set the "IsShowingPlaceholderText" property to "true" to treat the
// structured document tag's current contents as placeholder text.
// This means that clicking on the text box in Microsoft Word will immediately highlight all the tag's contents.
// Set the "IsShowingPlaceholderText" property to "false" to get the
// structured document tag to treat its contents as text that a user has already entered.
// Clicking on this text in Microsoft Word will place the blinking cursor at the clicked location.
tag.IsShowingPlaceholderText = isShowingPlaceholderText;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
substituteBlock = (BuildingBlock)doc.GlossaryDocument.GetChild(NodeType.BuildingBlock, 0, true);
Assert.AreEqual("Custom Placeholder", substituteBlock.Name);
Assert.AreEqual(isShowingPlaceholderText, tag.IsShowingPlaceholderText);
Assert.AreEqual(substituteBlock, tag.Placeholder);
Assert.AreEqual(substituteBlock.Name, tag.PlaceholderName);
}
Project:starred-repos
File:ExStructuredDocumentTag.cs
Examples:6
[Test]
public void RepeatingSection()
{
//ExStart
//ExFor:StructuredDocumentTag.SdtType
//ExSummary:Shows how to get the type of a structured document tag.
Document doc = new Document(MyDir + "Structured document tags.docx");
List<StructuredDocumentTag> sdTags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true)
.OfType<StructuredDocumentTag>().ToList();
Assert.AreEqual(SdtType.RepeatingSection, sdTags[0].SdtType);
Assert.AreEqual(SdtType.RepeatingSectionItem, sdTags[1].SdtType);
Assert.AreEqual(SdtType.RichText, sdTags[2].SdtType);
//ExEnd
}
[Test]
public void ApplyStyle()
{
//ExStart
//ExFor:StructuredDocumentTag
//ExFor:StructuredDocumentTag.NodeType
//ExFor:StructuredDocumentTag.Style
//ExFor:StructuredDocumentTag.StyleName
//ExFor:MarkupLevel
//ExFor:SdtType
//ExSummary:Shows how to work with styles for content control elements.
Document doc = new Document();
DocumentBuilder builder = new 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:
Style quoteStyle = doc.Styles[StyleIdentifier.Quote];
StructuredDocumentTag sdtPlainText =
new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline) { Style = quoteStyle };
// 2 - Reference a style in the document by name:
StructuredDocumentTag sdtRichText =
new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline) { StyleName = "Quote" };
builder.InsertNode(sdtPlainText);
builder.InsertNode(sdtRichText);
Assert.AreEqual(NodeType.StructuredDocumentTag, sdtPlainText.NodeType);
NodeCollection tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (Node node in tags)
{
StructuredDocumentTag sdt = (StructuredDocumentTag)node;
Assert.AreEqual(StyleIdentifier.Quote, sdt.Style.StyleIdentifier);
Assert.AreEqual("Quote", sdt.StyleName);
}
//ExEnd
}
[Test]
public void CheckBox()
{
//ExStart
//ExFor:StructuredDocumentTag.#ctor(DocumentBase, SdtType, MarkupLevel)
//ExFor:StructuredDocumentTag.Checked
//ExFor:StructuredDocumentTag.SetCheckedSymbol(System.Int32, System.String)
//ExFor:StructuredDocumentTag.SetUncheckedSymbol(System.Int32, System.String)
//ExSummary:Show how to create a structured document tag in the form of a check box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
StructuredDocumentTag sdtCheckBox =
new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline) {Checked = true};
// We can set the symbols used to represent the checked/unchecked state of a checkbox content control.
sdtCheckBox.SetCheckedSymbol(0x00A9, "Times New Roman");
sdtCheckBox.SetUncheckedSymbol(0x00AE, "Times New Roman");
builder.InsertNode(sdtCheckBox);
doc.Save(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
StructuredDocumentTag[] tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true)
.OfType<StructuredDocumentTag>().ToArray();
Assert.AreEqual(true, tags[0].Checked);
Assert.That(tags[0].XmlMapping.StoreItemId, Is.Empty);
}
#if NET48 || NET5_0 || JAVA // because of a Xamarin bug with CultureInfo (https://xamarin.github.io/bugzilla-archives/59/59077/bug.html)
[Test, Category("SkipMono")]
public void Date()
{
//ExStart
//ExFor:StructuredDocumentTag.CalendarType
//ExFor:StructuredDocumentTag.DateDisplayFormat
//ExFor:StructuredDocumentTag.DateDisplayLocale
//ExFor:StructuredDocumentTag.DateStorageFormat
//ExFor:StructuredDocumentTag.FullDate
//ExSummary:Shows how to prompt the user to enter a date with a structured document tag.
Document doc = new Document();
// Insert a structured document tag that prompts the user to enter a date.
// In Microsoft Word, this element is known as a "Date picker content control".
// When we click on the arrow on the right end of this tag in Microsoft Word,
// we will see a pop up in the form of a clickable calendar.
// We can use that popup to select a date that the tag will display.
StructuredDocumentTag sdtDate = new StructuredDocumentTag(doc, SdtType.Date, MarkupLevel.Inline);
// Display the date, according to the Saudi Arabian Arabic locale.
sdtDate.DateDisplayLocale = CultureInfo.GetCultureInfo("ar-SA").LCID;
// Set the format with which to display the date.
sdtDate.DateDisplayFormat = "dd MMMM, yyyy";
sdtDate.DateStorageFormat = SdtDateStorageFormat.DateTime;
// Display the date according to the Hijri calendar.
sdtDate.CalendarType = SdtCalendarType.Hijri;
// Before the user chooses a date in Microsoft Word, the tag will display the text "Click here to enter a date.".
// According to the tag's calendar, set the "FullDate" property to get the tag to display a default date.
sdtDate.FullDate = new DateTime(1440, 10, 20);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(sdtDate);
doc.Save(ArtifactsDir + "StructuredDocumentTag.Date.docx");
//ExEnd
}
#endif
[Test]
public void PlainText()
{
//ExStart
//ExFor:StructuredDocumentTag.Color
//ExFor:StructuredDocumentTag.ContentsFont
//ExFor:StructuredDocumentTag.EndCharacterFont
//ExFor:StructuredDocumentTag.Id
//ExFor:StructuredDocumentTag.Level
//ExFor:StructuredDocumentTag.Multiline
//ExFor:StructuredDocumentTag.Tag
//ExFor:StructuredDocumentTag.Title
//ExFor:StructuredDocumentTag.RemoveSelfOnly
//ExFor:StructuredDocumentTag.Appearance
//ExSummary:Shows how to create a structured document tag in a plain text box and modify its appearance.
Document doc = new Document();
// Create a structured document tag that will contain plain text.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the title and color of the frame that appears when you mouse over the structured document tag in Microsoft Word.
tag.Title = "My plain text";
tag.Color = Color.Magenta;
// Set a tag for this structured document tag, which is obtainable
// as an XML element named "tag", with the string below in its "@val" attribute.
tag.Tag = "MyPlainTextSDT";
// Every structured document tag has a random unique ID.
Assert.That(tag.Id, Is.Positive);
// Set the font for the text inside the structured document tag.
tag.ContentsFont.Name = "Arial";
// Set the font for the text at the end of the structured document tag.
// Any text that we type in the document body after moving out of the tag with arrow keys will use this font.
tag.EndCharacterFont.Name = "Arial Black";
// By default, this is false and pressing enter while inside a structured document tag does nothing.
// When set to true, our structured document tag can have multiple lines.
// Set the "Multiline" property to "false" to only allow the contents
// of this structured document tag to span a single line.
// Set the "Multiline" property to "true" to allow the tag to contain multiple lines of content.
tag.Multiline = true;
// Set the "Appearance" property to "SdtAppearance.Tags" to show tags around content.
// By default structured document tag shows as BoundingBox.
tag.Appearance = SdtAppearance.Tags;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
// Insert a clone of our structured document tag in a new paragraph.
StructuredDocumentTag tagClone = (StructuredDocumentTag)tag.Clone(true);
builder.InsertParagraph();
builder.InsertNode(tagClone);
// Use the "RemoveSelfOnly" method to remove a structured document tag, while keeping its contents in the document.
tagClone.RemoveSelfOnly();
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
Assert.AreEqual("My plain text", tag.Title);
Assert.AreEqual(Color.Magenta.ToArgb(), tag.Color.ToArgb());
Assert.AreEqual("MyPlainTextSDT", tag.Tag);
Assert.That(tag.Id, Is.Positive);
Assert.AreEqual("Arial", tag.ContentsFont.Name);
Assert.AreEqual("Arial Black", tag.EndCharacterFont.Name);
Assert.True(tag.Multiline);
Assert.AreEqual(SdtAppearance.Tags, tag.Appearance);
}
[TestCase(false)]
[TestCase(true)]
public void IsTemporary(bool isTemporary)
{
//ExStart
//ExFor:StructuredDocumentTag.IsTemporary
//ExSummary:Shows how to make single-use controls.
Document doc = new Document();
// Insert a plain text structured document tag,
// which will act as a plain text form that the user may enter text into.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the "IsTemporary" property to "true" to make the structured document tag disappear and
// assimilate its contents into the document after the user edits it once in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to edit the contents
// of the structured document tag any number of times.
tag.IsTemporary = isTemporary;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Please enter text: ");
builder.InsertNode(tag);
// Insert another structured document tag in the form of a check box and set its default state to "checked".
tag = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
tag.Checked = true;
// Set the "IsTemporary" property to "true" to make the check box become a symbol
// once the user clicks on it in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to click on the check box any number of times.
tag.IsTemporary = isTemporary;
builder.Write("\nPlease click the check box: ");
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
Assert.AreEqual(2,
doc.GetChildNodes(NodeType.StructuredDocumentTag, true).Count(sdt => ((StructuredDocumentTag)sdt).IsTemporary == isTemporary));
}
[TestCase(false)]
[TestCase(true)]
public void PlaceholderBuildingBlock(bool isShowingPlaceholderText)
{
//ExStart
//ExFor:StructuredDocumentTag.IsShowingPlaceholderText
//ExFor:StructuredDocumentTag.Placeholder
//ExFor:StructuredDocumentTag.PlaceholderName
//ExSummary:Shows how to use a building block's contents as a custom placeholder text for a structured document tag.
Document doc = new Document();
// Insert a plain text structured document tag of the "PlainText" type, which will function as a text box.
// The contents that it will display by default are a "Click here to enter text." prompt.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// We can get the tag to display the contents of a building block instead of the default text.
// First, add a building block with contents to the glossary document.
GlossaryDocument glossaryDoc = doc.GlossaryDocument;
BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc);
substituteBlock.Name = "Custom Placeholder";
substituteBlock.AppendChild(new Section(glossaryDoc));
substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));
substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text.");
glossaryDoc.AppendChild(substituteBlock);
// Then, use the structured document tag's "PlaceholderName" property to reference that building block by name.
tag.PlaceholderName = "Custom Placeholder";
// If "PlaceholderName" refers to an existing block in the parent document's glossary document,
// we will be able to verify the building block via the "Placeholder" property.
Assert.AreEqual(substituteBlock, tag.Placeholder);
// Set the "IsShowingPlaceholderText" property to "true" to treat the
// structured document tag's current contents as placeholder text.
// This means that clicking on the text box in Microsoft Word will immediately highlight all the tag's contents.
// Set the "IsShowingPlaceholderText" property to "false" to get the
// structured document tag to treat its contents as text that a user has already entered.
// Clicking on this text in Microsoft Word will place the blinking cursor at the clicked location.
tag.IsShowingPlaceholderText = isShowingPlaceholderText;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
substituteBlock = (BuildingBlock)doc.GlossaryDocument.GetChild(NodeType.BuildingBlock, 0, true);
Assert.AreEqual("Custom Placeholder", substituteBlock.Name);
Assert.AreEqual(isShowingPlaceholderText, tag.IsShowingPlaceholderText);
Assert.AreEqual(substituteBlock, tag.Placeholder);
Assert.AreEqual(substituteBlock.Name, tag.PlaceholderName);
}
Project:starred-repos
File:ExStructuredDocumentTag.cs
Examples:6
[Test]
public void RepeatingSection()
{
//ExStart
//ExFor:StructuredDocumentTag.SdtType
//ExSummary:Shows how to get the type of a structured document tag.
Document doc = new Document(MyDir + "Structured document tags.docx");
List<StructuredDocumentTag> sdTags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true)
.OfType<StructuredDocumentTag>().ToList();
Assert.AreEqual(SdtType.RepeatingSection, sdTags[0].SdtType);
Assert.AreEqual(SdtType.RepeatingSectionItem, sdTags[1].SdtType);
Assert.AreEqual(SdtType.RichText, sdTags[2].SdtType);
//ExEnd
}
[Test]
public void ApplyStyle()
{
//ExStart
//ExFor:StructuredDocumentTag
//ExFor:StructuredDocumentTag.NodeType
//ExFor:StructuredDocumentTag.Style
//ExFor:StructuredDocumentTag.StyleName
//ExFor:MarkupLevel
//ExFor:SdtType
//ExSummary:Shows how to work with styles for content control elements.
Document doc = new Document();
DocumentBuilder builder = new 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:
Style quoteStyle = doc.Styles[StyleIdentifier.Quote];
StructuredDocumentTag sdtPlainText =
new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline) { Style = quoteStyle };
// 2 - Reference a style in the document by name:
StructuredDocumentTag sdtRichText =
new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline) { StyleName = "Quote" };
builder.InsertNode(sdtPlainText);
builder.InsertNode(sdtRichText);
Assert.AreEqual(NodeType.StructuredDocumentTag, sdtPlainText.NodeType);
NodeCollection tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (Node node in tags)
{
StructuredDocumentTag sdt = (StructuredDocumentTag)node;
Assert.AreEqual(StyleIdentifier.Quote, sdt.Style.StyleIdentifier);
Assert.AreEqual("Quote", sdt.StyleName);
}
//ExEnd
}
[Test]
public void CheckBox()
{
//ExStart
//ExFor:StructuredDocumentTag.#ctor(DocumentBase, SdtType, MarkupLevel)
//ExFor:StructuredDocumentTag.Checked
//ExFor:StructuredDocumentTag.SetCheckedSymbol(System.Int32, System.String)
//ExFor:StructuredDocumentTag.SetUncheckedSymbol(System.Int32, System.String)
//ExSummary:Show how to create a structured document tag in the form of a check box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
StructuredDocumentTag sdtCheckBox =
new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline) {Checked = true};
// We can set the symbols used to represent the checked/unchecked state of a checkbox content control.
sdtCheckBox.SetCheckedSymbol(0x00A9, "Times New Roman");
sdtCheckBox.SetUncheckedSymbol(0x00AE, "Times New Roman");
builder.InsertNode(sdtCheckBox);
doc.Save(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
StructuredDocumentTag[] tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true)
.OfType<StructuredDocumentTag>().ToArray();
Assert.AreEqual(true, tags[0].Checked);
Assert.That(tags[0].XmlMapping.StoreItemId, Is.Empty);
}
#if NET48 || NET5_0 || JAVA // because of a Xamarin bug with CultureInfo (https://xamarin.github.io/bugzilla-archives/59/59077/bug.html)
[Test, Category("SkipMono")]
public void Date()
{
//ExStart
//ExFor:StructuredDocumentTag.CalendarType
//ExFor:StructuredDocumentTag.DateDisplayFormat
//ExFor:StructuredDocumentTag.DateDisplayLocale
//ExFor:StructuredDocumentTag.DateStorageFormat
//ExFor:StructuredDocumentTag.FullDate
//ExSummary:Shows how to prompt the user to enter a date with a structured document tag.
Document doc = new Document();
// Insert a structured document tag that prompts the user to enter a date.
// In Microsoft Word, this element is known as a "Date picker content control".
// When we click on the arrow on the right end of this tag in Microsoft Word,
// we will see a pop up in the form of a clickable calendar.
// We can use that popup to select a date that the tag will display.
StructuredDocumentTag sdtDate = new StructuredDocumentTag(doc, SdtType.Date, MarkupLevel.Inline);
// Display the date, according to the Saudi Arabian Arabic locale.
sdtDate.DateDisplayLocale = CultureInfo.GetCultureInfo("ar-SA").LCID;
// Set the format with which to display the date.
sdtDate.DateDisplayFormat = "dd MMMM, yyyy";
sdtDate.DateStorageFormat = SdtDateStorageFormat.DateTime;
// Display the date according to the Hijri calendar.
sdtDate.CalendarType = SdtCalendarType.Hijri;
// Before the user chooses a date in Microsoft Word, the tag will display the text "Click here to enter a date.".
// According to the tag's calendar, set the "FullDate" property to get the tag to display a default date.
sdtDate.FullDate = new DateTime(1440, 10, 20);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(sdtDate);
doc.Save(ArtifactsDir + "StructuredDocumentTag.Date.docx");
//ExEnd
}
#endif
[Test]
public void PlainText()
{
//ExStart
//ExFor:StructuredDocumentTag.Color
//ExFor:StructuredDocumentTag.ContentsFont
//ExFor:StructuredDocumentTag.EndCharacterFont
//ExFor:StructuredDocumentTag.Id
//ExFor:StructuredDocumentTag.Level
//ExFor:StructuredDocumentTag.Multiline
//ExFor:StructuredDocumentTag.Tag
//ExFor:StructuredDocumentTag.Title
//ExFor:StructuredDocumentTag.RemoveSelfOnly
//ExFor:StructuredDocumentTag.Appearance
//ExSummary:Shows how to create a structured document tag in a plain text box and modify its appearance.
Document doc = new Document();
// Create a structured document tag that will contain plain text.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the title and color of the frame that appears when you mouse over the structured document tag in Microsoft Word.
tag.Title = "My plain text";
tag.Color = Color.Magenta;
// Set a tag for this structured document tag, which is obtainable
// as an XML element named "tag", with the string below in its "@val" attribute.
tag.Tag = "MyPlainTextSDT";
// Every structured document tag has a random unique ID.
Assert.That(tag.Id, Is.Positive);
// Set the font for the text inside the structured document tag.
tag.ContentsFont.Name = "Arial";
// Set the font for the text at the end of the structured document tag.
// Any text that we type in the document body after moving out of the tag with arrow keys will use this font.
tag.EndCharacterFont.Name = "Arial Black";
// By default, this is false and pressing enter while inside a structured document tag does nothing.
// When set to true, our structured document tag can have multiple lines.
// Set the "Multiline" property to "false" to only allow the contents
// of this structured document tag to span a single line.
// Set the "Multiline" property to "true" to allow the tag to contain multiple lines of content.
tag.Multiline = true;
// Set the "Appearance" property to "SdtAppearance.Tags" to show tags around content.
// By default structured document tag shows as BoundingBox.
tag.Appearance = SdtAppearance.Tags;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
// Insert a clone of our structured document tag in a new paragraph.
StructuredDocumentTag tagClone = (StructuredDocumentTag)tag.Clone(true);
builder.InsertParagraph();
builder.InsertNode(tagClone);
// Use the "RemoveSelfOnly" method to remove a structured document tag, while keeping its contents in the document.
tagClone.RemoveSelfOnly();
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
Assert.AreEqual("My plain text", tag.Title);
Assert.AreEqual(Color.Magenta.ToArgb(), tag.Color.ToArgb());
Assert.AreEqual("MyPlainTextSDT", tag.Tag);
Assert.That(tag.Id, Is.Positive);
Assert.AreEqual("Arial", tag.ContentsFont.Name);
Assert.AreEqual("Arial Black", tag.EndCharacterFont.Name);
Assert.True(tag.Multiline);
Assert.AreEqual(SdtAppearance.Tags, tag.Appearance);
}
[TestCase(false)]
[TestCase(true)]
public void IsTemporary(bool isTemporary)
{
//ExStart
//ExFor:StructuredDocumentTag.IsTemporary
//ExSummary:Shows how to make single-use controls.
Document doc = new Document();
// Insert a plain text structured document tag,
// which will act as a plain text form that the user may enter text into.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the "IsTemporary" property to "true" to make the structured document tag disappear and
// assimilate its contents into the document after the user edits it once in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to edit the contents
// of the structured document tag any number of times.
tag.IsTemporary = isTemporary;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Please enter text: ");
builder.InsertNode(tag);
// Insert another structured document tag in the form of a check box and set its default state to "checked".
tag = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
tag.Checked = true;
// Set the "IsTemporary" property to "true" to make the check box become a symbol
// once the user clicks on it in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to click on the check box any number of times.
tag.IsTemporary = isTemporary;
builder.Write("\nPlease click the check box: ");
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
Assert.AreEqual(2,
doc.GetChildNodes(NodeType.StructuredDocumentTag, true).Count(sdt => ((StructuredDocumentTag)sdt).IsTemporary == isTemporary));
}
[TestCase(false)]
[TestCase(true)]
public void PlaceholderBuildingBlock(bool isShowingPlaceholderText)
{
//ExStart
//ExFor:StructuredDocumentTag.IsShowingPlaceholderText
//ExFor:StructuredDocumentTag.Placeholder
//ExFor:StructuredDocumentTag.PlaceholderName
//ExSummary:Shows how to use a building block's contents as a custom placeholder text for a structured document tag.
Document doc = new Document();
// Insert a plain text structured document tag of the "PlainText" type, which will function as a text box.
// The contents that it will display by default are a "Click here to enter text." prompt.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// We can get the tag to display the contents of a building block instead of the default text.
// First, add a building block with contents to the glossary document.
GlossaryDocument glossaryDoc = doc.GlossaryDocument;
BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc);
substituteBlock.Name = "Custom Placeholder";
substituteBlock.AppendChild(new Section(glossaryDoc));
substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));
substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text.");
glossaryDoc.AppendChild(substituteBlock);
// Then, use the structured document tag's "PlaceholderName" property to reference that building block by name.
tag.PlaceholderName = "Custom Placeholder";
// If "PlaceholderName" refers to an existing block in the parent document's glossary document,
// we will be able to verify the building block via the "Placeholder" property.
Assert.AreEqual(substituteBlock, tag.Placeholder);
// Set the "IsShowingPlaceholderText" property to "true" to treat the
// structured document tag's current contents as placeholder text.
// This means that clicking on the text box in Microsoft Word will immediately highlight all the tag's contents.
// Set the "IsShowingPlaceholderText" property to "false" to get the
// structured document tag to treat its contents as text that a user has already entered.
// Clicking on this text in Microsoft Word will place the blinking cursor at the clicked location.
tag.IsShowingPlaceholderText = isShowingPlaceholderText;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
substituteBlock = (BuildingBlock)doc.GlossaryDocument.GetChild(NodeType.BuildingBlock, 0, true);
Assert.AreEqual("Custom Placeholder", substituteBlock.Name);
Assert.AreEqual(isShowingPlaceholderText, tag.IsShowingPlaceholderText);
Assert.AreEqual(substituteBlock, tag.Placeholder);
Assert.AreEqual(substituteBlock.Name, tag.PlaceholderName);
}
Project:Aspose.Words-for-.NET
File:ExStructuredDocumentTag.cs
Examples:6
[Test]
public void RepeatingSection()
{
//ExStart
//ExFor:StructuredDocumentTag.SdtType
//ExSummary:Shows how to get the type of a structured document tag.
Document doc = new Document(MyDir + "Structured document tags.docx");
List<StructuredDocumentTag> sdTags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true)
.OfType<StructuredDocumentTag>().ToList();
Assert.AreEqual(SdtType.RepeatingSection, sdTags[0].SdtType);
Assert.AreEqual(SdtType.RepeatingSectionItem, sdTags[1].SdtType);
Assert.AreEqual(SdtType.RichText, sdTags[2].SdtType);
//ExEnd
}
[Test]
public void ApplyStyle()
{
//ExStart
//ExFor:StructuredDocumentTag
//ExFor:StructuredDocumentTag.NodeType
//ExFor:StructuredDocumentTag.Style
//ExFor:StructuredDocumentTag.StyleName
//ExFor:MarkupLevel
//ExFor:SdtType
//ExSummary:Shows how to work with styles for content control elements.
Document doc = new Document();
DocumentBuilder builder = new 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:
Style quoteStyle = doc.Styles[StyleIdentifier.Quote];
StructuredDocumentTag sdtPlainText =
new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline) { Style = quoteStyle };
// 2 - Reference a style in the document by name:
StructuredDocumentTag sdtRichText =
new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline) { StyleName = "Quote" };
builder.InsertNode(sdtPlainText);
builder.InsertNode(sdtRichText);
Assert.AreEqual(NodeType.StructuredDocumentTag, sdtPlainText.NodeType);
NodeCollection tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (Node node in tags)
{
StructuredDocumentTag sdt = (StructuredDocumentTag)node;
Assert.AreEqual(StyleIdentifier.Quote, sdt.Style.StyleIdentifier);
Assert.AreEqual("Quote", sdt.StyleName);
}
//ExEnd
}
[Test]
public void CheckBox()
{
//ExStart
//ExFor:StructuredDocumentTag.#ctor(DocumentBase, SdtType, MarkupLevel)
//ExFor:StructuredDocumentTag.Checked
//ExFor:StructuredDocumentTag.SetCheckedSymbol(System.Int32, System.String)
//ExFor:StructuredDocumentTag.SetUncheckedSymbol(System.Int32, System.String)
//ExSummary:Show how to create a structured document tag in the form of a check box.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
StructuredDocumentTag sdtCheckBox =
new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline) {Checked = true};
// We can set the symbols used to represent the checked/unchecked state of a checkbox content control.
sdtCheckBox.SetCheckedSymbol(0x00A9, "Times New Roman");
sdtCheckBox.SetUncheckedSymbol(0x00AE, "Times New Roman");
builder.InsertNode(sdtCheckBox);
doc.Save(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.CheckBox.docx");
StructuredDocumentTag[] tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true)
.OfType<StructuredDocumentTag>().ToArray();
Assert.AreEqual(true, tags[0].Checked);
Assert.That(tags[0].XmlMapping.StoreItemId, Is.Empty);
}
#if NET48 || NET5_0 || JAVA // because of a Xamarin bug with CultureInfo (https://xamarin.github.io/bugzilla-archives/59/59077/bug.html)
[Test, Category("SkipMono")]
public void Date()
{
//ExStart
//ExFor:StructuredDocumentTag.CalendarType
//ExFor:StructuredDocumentTag.DateDisplayFormat
//ExFor:StructuredDocumentTag.DateDisplayLocale
//ExFor:StructuredDocumentTag.DateStorageFormat
//ExFor:StructuredDocumentTag.FullDate
//ExSummary:Shows how to prompt the user to enter a date with a structured document tag.
Document doc = new Document();
// Insert a structured document tag that prompts the user to enter a date.
// In Microsoft Word, this element is known as a "Date picker content control".
// When we click on the arrow on the right end of this tag in Microsoft Word,
// we will see a pop up in the form of a clickable calendar.
// We can use that popup to select a date that the tag will display.
StructuredDocumentTag sdtDate = new StructuredDocumentTag(doc, SdtType.Date, MarkupLevel.Inline);
// Display the date, according to the Saudi Arabian Arabic locale.
sdtDate.DateDisplayLocale = CultureInfo.GetCultureInfo("ar-SA").LCID;
// Set the format with which to display the date.
sdtDate.DateDisplayFormat = "dd MMMM, yyyy";
sdtDate.DateStorageFormat = SdtDateStorageFormat.DateTime;
// Display the date according to the Hijri calendar.
sdtDate.CalendarType = SdtCalendarType.Hijri;
// Before the user chooses a date in Microsoft Word, the tag will display the text "Click here to enter a date.".
// According to the tag's calendar, set the "FullDate" property to get the tag to display a default date.
sdtDate.FullDate = new DateTime(1440, 10, 20);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(sdtDate);
doc.Save(ArtifactsDir + "StructuredDocumentTag.Date.docx");
//ExEnd
}
#endif
[Test]
public void PlainText()
{
//ExStart
//ExFor:StructuredDocumentTag.Color
//ExFor:StructuredDocumentTag.ContentsFont
//ExFor:StructuredDocumentTag.EndCharacterFont
//ExFor:StructuredDocumentTag.Id
//ExFor:StructuredDocumentTag.Level
//ExFor:StructuredDocumentTag.Multiline
//ExFor:StructuredDocumentTag.Tag
//ExFor:StructuredDocumentTag.Title
//ExFor:StructuredDocumentTag.RemoveSelfOnly
//ExFor:StructuredDocumentTag.Appearance
//ExSummary:Shows how to create a structured document tag in a plain text box and modify its appearance.
Document doc = new Document();
// Create a structured document tag that will contain plain text.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the title and color of the frame that appears when you mouse over the structured document tag in Microsoft Word.
tag.Title = "My plain text";
tag.Color = Color.Magenta;
// Set a tag for this structured document tag, which is obtainable
// as an XML element named "tag", with the string below in its "@val" attribute.
tag.Tag = "MyPlainTextSDT";
// Every structured document tag has a random unique ID.
Assert.That(tag.Id, Is.Positive);
// Set the font for the text inside the structured document tag.
tag.ContentsFont.Name = "Arial";
// Set the font for the text at the end of the structured document tag.
// Any text that we type in the document body after moving out of the tag with arrow keys will use this font.
tag.EndCharacterFont.Name = "Arial Black";
// By default, this is false and pressing enter while inside a structured document tag does nothing.
// When set to true, our structured document tag can have multiple lines.
// Set the "Multiline" property to "false" to only allow the contents
// of this structured document tag to span a single line.
// Set the "Multiline" property to "true" to allow the tag to contain multiple lines of content.
tag.Multiline = true;
// Set the "Appearance" property to "SdtAppearance.Tags" to show tags around content.
// By default structured document tag shows as BoundingBox.
tag.Appearance = SdtAppearance.Tags;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
// Insert a clone of our structured document tag in a new paragraph.
StructuredDocumentTag tagClone = (StructuredDocumentTag)tag.Clone(true);
builder.InsertParagraph();
builder.InsertNode(tagClone);
// Use the "RemoveSelfOnly" method to remove a structured document tag, while keeping its contents in the document.
tagClone.RemoveSelfOnly();
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
Assert.AreEqual("My plain text", tag.Title);
Assert.AreEqual(Color.Magenta.ToArgb(), tag.Color.ToArgb());
Assert.AreEqual("MyPlainTextSDT", tag.Tag);
Assert.That(tag.Id, Is.Positive);
Assert.AreEqual("Arial", tag.ContentsFont.Name);
Assert.AreEqual("Arial Black", tag.EndCharacterFont.Name);
Assert.True(tag.Multiline);
Assert.AreEqual(SdtAppearance.Tags, tag.Appearance);
}
[TestCase(false)]
[TestCase(true)]
public void IsTemporary(bool isTemporary)
{
//ExStart
//ExFor:StructuredDocumentTag.IsTemporary
//ExSummary:Shows how to make single-use controls.
Document doc = new Document();
// Insert a plain text structured document tag,
// which will act as a plain text form that the user may enter text into.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// Set the "IsTemporary" property to "true" to make the structured document tag disappear and
// assimilate its contents into the document after the user edits it once in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to edit the contents
// of the structured document tag any number of times.
tag.IsTemporary = isTemporary;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Please enter text: ");
builder.InsertNode(tag);
// Insert another structured document tag in the form of a check box and set its default state to "checked".
tag = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
tag.Checked = true;
// Set the "IsTemporary" property to "true" to make the check box become a symbol
// once the user clicks on it in Microsoft Word.
// Set the "IsTemporary" property to "false" to allow the user to click on the check box any number of times.
tag.IsTemporary = isTemporary;
builder.Write("\nPlease click the check box: ");
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.IsTemporary.docx");
Assert.AreEqual(2,
doc.GetChildNodes(NodeType.StructuredDocumentTag, true).Count(sdt => ((StructuredDocumentTag)sdt).IsTemporary == isTemporary));
}
[TestCase(false)]
[TestCase(true)]
public void PlaceholderBuildingBlock(bool isShowingPlaceholderText)
{
//ExStart
//ExFor:StructuredDocumentTag.IsShowingPlaceholderText
//ExFor:StructuredDocumentTag.Placeholder
//ExFor:StructuredDocumentTag.PlaceholderName
//ExSummary:Shows how to use a building block's contents as a custom placeholder text for a structured document tag.
Document doc = new Document();
// Insert a plain text structured document tag of the "PlainText" type, which will function as a text box.
// The contents that it will display by default are a "Click here to enter text." prompt.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);
// We can get the tag to display the contents of a building block instead of the default text.
// First, add a building block with contents to the glossary document.
GlossaryDocument glossaryDoc = doc.GlossaryDocument;
BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc);
substituteBlock.Name = "Custom Placeholder";
substituteBlock.AppendChild(new Section(glossaryDoc));
substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));
substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text.");
glossaryDoc.AppendChild(substituteBlock);
// Then, use the structured document tag's "PlaceholderName" property to reference that building block by name.
tag.PlaceholderName = "Custom Placeholder";
// If "PlaceholderName" refers to an existing block in the parent document's glossary document,
// we will be able to verify the building block via the "Placeholder" property.
Assert.AreEqual(substituteBlock, tag.Placeholder);
// Set the "IsShowingPlaceholderText" property to "true" to treat the
// structured document tag's current contents as placeholder text.
// This means that clicking on the text box in Microsoft Word will immediately highlight all the tag's contents.
// Set the "IsShowingPlaceholderText" property to "false" to get the
// structured document tag to treat its contents as text that a user has already entered.
// Clicking on this text in Microsoft Word will place the blinking cursor at the clicked location.
tag.IsShowingPlaceholderText = isShowingPlaceholderText;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);
doc.Save(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
//ExEnd
doc = new Document(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
substituteBlock = (BuildingBlock)doc.GlossaryDocument.GetChild(NodeType.BuildingBlock, 0, true);
Assert.AreEqual("Custom Placeholder", substituteBlock.Name);
Assert.AreEqual(isShowingPlaceholderText, tag.IsShowingPlaceholderText);
Assert.AreEqual(substituteBlock, tag.Placeholder);
Assert.AreEqual(substituteBlock.Name, tag.PlaceholderName);
}
Aspose.Words.Markup.SdtListItemCollection : IEnumerable
Methods :
public IEnumerator<SdtListItem> GetEnumerator()public Void Add(SdtListItem item = )
public Void RemoveAt(Int32 index = )
public Void Clear()
public SdtListItem get_SelectedValue()
public Void set_SelectedValue(SdtListItem value = )
public SdtListItem get_Item(Int32 index = )
public Int32 get_Count()
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()