Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Extend Existing Controls

  • Last UpdatedNov 15, 2023
  • 2 minute read

Create a custom control by inheriting and extending from an existing forms control to leverage the features of the existing control.

When a custom control class inherits from one of the existing forms control class and the ICustomControl interface, the custom control has access to all the features of the existing forms control. You can extend the forms control by overriding the existing properties and functionalities of the forms control class.

Use GetViewModelDefinition() function to make use of the existing forms control properties by assigning values to the existing forms control property using the base keyword. Override GetControlTypeName property and return the base type of the control to inherit all features of the existing control.

Example: Inheriting all features of Text Control

Custom control inheriting all features from the Text control class:

public override string GetControlTypeName

{

get

{

return typeof(TextInput).Name;

}

}

Example: Inheriting Text Control

Custom control inheriting from the Text control class:

[DesignerControl(992200, CoreDesigner.NextGenDesigner, DesignerCategory.Custom)]

public class FirstName: TextInput, ICustomControl

Example: Extending ViewModelDefinition() and ViewModelScript() functions

public override string GetViewModelDefinition()

{

 base.MaxLength = 10;

 base.MinLength = 4;

 return base.GetViewModelDefinition();

}

public override string GetViewModelScript()

{

 string code = string.Empty;

 var valueScript = this.PropertyExpressions.Where(e => e.Name == "Value").ToList();

 if (valueScript.Count == 0)

 {

 string retVal = "Test Value";

 code = "if(currentValue==\"" + string.Empty + "\"" + "){ return \"" + retVal + "\"" + ";} else{ return currentValue; }";

 this.PropertyExpressions.Add(new Property("Value", code));

 }

 var validateScript = this.PropertyExpressions.Where(e => e.Name == "Validate").ToList();

 if (validateScript.Count == 0)

 {

 string comma = ",";

 string validationmsg = "Comma (,) is not a valid character";

 code = "if(currentValue.indexOf(\"" + comma + "\"" + ") > -1){ return new ValidationOptions(false, \"" + validationmsg + "\"" + ");} else { return new ValidationOptions(true, \"" + string.Empty + "\"" + "); }";

 this.PropertyExpressions.Add(new Property("Validate", code));

 }

 return base.GetViewModelScript();

}

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in