다음을 통해 공유


Exposing Methods and Properties in a Windows Client Control Add-in

Control add-ins let you add custom user interface (UI) controls to pages in the Microsoft Dynamics NAV Windows client. By using the basic control add-in definition interfaces, a control add-in is bound to a page only through the field that is applied with the control add-in. It is also bound to the page through the SourceExpr Property, the OnControlAddin Trigger, and other triggers for exposed events. To extend UI controls on a page, you can expose methods and properties in a control add-in assembly so that they can be called by C/AL code on most page triggers.

Exposing Methods and Properties

To expose a public method or property in a control add-in, you add the method or property to the control add-in class and mark it by using the managed attribute Microsoft.Dynamics.Framework.UI.Extensibility.ApplicationVisibleAttribute in control add-in class.

The following code example is from a control add-in class that exposes a simple method and property.

[ControlAddInExport("MyControlAddIn")]
public class MyControlAddIn : WinFormsControlAddInBase, ...
{
    ...
    
    //Exposes a method
    [ApplicationVisible]
    public string Add(int param1, int param2)
    {
        return FormatNumber(param1 + param2, this.Notation);
    }
    
    //Exposes a property
    [ApplicationVisible]
    public Notation Notation
    {
        get { return this.notation; }
        set { this.notation = value; }
    }

Calling Methods and Properties in the Control Add-in From C/AL Triggers

Exposed methods and properties in a control add-in can be invoked from C/AL code on page triggers. The invoking mechanism resembles other .NET Framework types with the .NET Framework interoperability except that you can call the control add-in methods and properties using C/AL without defining a variable.

To call a method in C/AL code on a page trigger, use the following code.

CurrPage.ControlName.MyMethod(parameter)

To call a property in C/AL code, use the following code.

CurrPage.ControlName.MyProperty

ControlName is the name of the field control that is applied with the control add-in. The name is specified by the Name Property. MyMethod and MyProperty are the names of method and property of the control add-in to be invoked.

Triggers That Are Not Supported

You cannot invoke control add-in methods and properties from the following triggers because the triggers are invoked before the page is instantiated:

See Also

Tasks

How to: Create a Windows Client Control Add-in

Concepts

Extending the Windows Client Using Control Add-ins
Extending Microsoft Dynamics NAV Using Microsoft .NET Framework Interoperability