TX Text Control .NET for WPF

Add Method

Method|Introduced in 28.0
Namespace
TXTextControl
Package
TXTextControl.TextControl.WPF.SDK as TXTextControl.dll from the private NuGet feed or Text Control Offline Packages

Description

Inserts an instance of the class ConditionalInstruction to the collection and the document.

Syntax

public bool Add(ConditionalInstruction conditionalInstruction);

Parameters

ParameterDescription
conditionalInstruction

Specifies ConditionalInstruction element to add.

Return Value

The return value is true, if the ConditionalInstruction could be added. Otherwise false. A ConditionalInstruction element won't be added, if the TextControl.IsFormFieldValidationEnabled property is set to false or the TextControl.EditMode is set to EditMode.ReadAndSelect and TextControl.DocumentPermissions.ReadOnly to true.

Examples

The following example registers a conditional rule for an approval check box in a fillable form.

CheckFormField approval = new(false) { Name = "Approved" };
textControl.FormFields.Add(approval);
ConditionalInstruction rule = new()
{
    Conditions = new[] { new Condition(approval, true) },
    Instructions = new[] { new Instruction(approval, Instruction.InstructionTypes.IsEnabled, true) }
};

if (!textControl.FormFields.ConditionalInstructions.Add(rule))
{
    throw new InvalidOperationException("The approval rule could not be added.");
}

Remarks

A System.ArgumentException is thrown, if the Name property value of the added ConditionalInstruction object is null or already exists as the name of another ConditionalInstruction inside the collection. Furthermore an exception is thrown, if the ConditionalInstruction's Condtions or Instructions properties values do not contain elements.