//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.Collections.Generic;usingSystem.Linq;usingGrapeCity.Documents.Word; namespaceDsWordWeb.Demos{// This example shows how to create and use a linked style,// which can be used as both a paragraph and a character style.publicclassLinkedStyle {publicGcWordDocumentCreateDocx() {var log = newList<string>();voidLog(string message) { log.Add(message); } var doc = newGcWordDocument();// Change the default: doc.HideLinkedCharacterStyles = false; // Create a linked style:var linkedStyle = doc.Styles.AddLinkedStyle("Linked Style", doc.Styles[BuiltInStyleId.Heading1]);Log($"Linked paragraph style is linked: {linkedStyle.Linked}"); // Linked paragraph style is linked: TrueLog($"Linked paragraph style name: {linkedStyle.Name}"); // Linked paragraph style name: Linked Style Log($"Linked paragraph style type: {linkedStyle.Type}"); // Linked paragraph style type: ParagraphLog($"Linked character style is linked: {linkedStyle.LinkStyle.Linked}"); // Linked character style is linked: TrueLog($"Linked character style name: {linkedStyle.LinkStyle.Name}"); // Linked character style name: Linked Style CharLog($"Linked character style type: {linkedStyle.LinkStyle.Type}"); // Linked character style type: Character // Change the linked style's formatting (reflects on both linked styles): linkedStyle.Font.Bold = true;Log($"Linked paragraph style is bold: {linkedStyle.Font.Bold}"); // Linked paragraph style is bold: TrueLog($"Linked character style is bold: {linkedStyle.LinkStyle.Font.Bold}"); // Linked character style is bold: True // Apply the linked style to a paragraph: doc.Body.Paragraphs.Add("This paragraph is formatted with a linked style that is applied to the whole paragraph as a paragraph style.", linkedStyle); // Apply the linked style to a run:var paragraph = doc.Body.Paragraphs.Add("In this paragraph, ", doc.Styles[BuiltInStyleId.Normal]);var run = paragraph.GetRange().Runs.Add("this run is formatted with the same linked style applied to the run as a character style.", linkedStyle); Log($"HideLinkedCharacterStyles is: {doc.HideLinkedCharacterStyles}"); // HideLinkedCharacterStyles is: FalseLog($"Styles collection has character linked styles: {doc.Styles.FirstOrDefault(x => x.Linked && x.Type == StyleType.Character) != null}"); // Style collection has character linked styles: TrueLog($"Run style name: {run.Style.Name}"); // Run style name: Linked Style Char // Toggle the HideLinkedCharacterStyles property: doc.HideLinkedCharacterStyles = true;Log($"HideLinkedCharacterStyles is: {doc.HideLinkedCharacterStyles}"); // HideLinkedCharacterStyles is: TrueLog($"Styles collection has character linked styles: {doc.Styles.FirstOrDefault(x => x.Linked && x.Type == StyleType.Character) != null}"); // Style collection has character linked styles: FalseLog($"Run style name: {run.Style.Name}"); // Run style name: Linked Style doc.Body.Paragraphs.Add("Log (see example code for details):", doc.Styles[BuiltInStyleId.Heading2]); log.ForEach(m_ => doc.Body.Paragraphs.Add(m_, doc.Styles[BuiltInStyleId.NoSpacing])); // Done:return doc; } }}