Skip to main content

GetBackgroundColor

Returns the background color of the current content control.

Syntax​

expression.GetBackgroundColor();

expression - A variable that represents an ApiInlineLvlSdt class.

Parameters​

This method doesn't have any parameters.

Returns​

ApiColor

Example​

Read the background color of an inline content control in a document.

// How do I get the background color of an inline content control in a document?

// Compare the fill color of multiple content controls to audit their visual styling in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let inlineLvlSdt = Api.CreateInlineLvlSdt();
let run = Api.CreateRun();
inlineLvlSdt.SetBackgroundColor(Api.RGBA(0, 0, 255, 40));
let color = inlineLvlSdt.GetBackgroundColor();
run.AddText("BackgroundColor: " + (color ? color.GetHex() : "none"));
inlineLvlSdt.AddElement(run, 0);
paragraph.AddInlineLvlSdt(inlineLvlSdt);

inlineLvlSdt = Api.CreateInlineLvlSdt();
run = Api.CreateRun();
color = inlineLvlSdt.GetBackgroundColor();
run.AddText("BackgroundColor: " + (color ? color.GetHex() : "none"));
inlineLvlSdt.AddElement(run, 0);
paragraph.AddInlineLvlSdt(inlineLvlSdt);