Skip to main content

Workflow Form Element Reference

In the VertiGIS Studio Workflow .NET SDK, all custom form elements must implement IFormComponent. However, it is typically easier to extend the ContentComponent class, which is the recommended practice. The examples shown here extend ContentComponent.

App1/App1/workflow/CustomFormElement.xaml
<?xml version="1.0" encoding="UTF-8"?><core:ContentComponent xmlns="http://xamarin.com/schemas/2014/forms"                       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"                       xmlns:core="clr-namespace:VertiGIS.Mobile.Workflow.Core;assembly=VertiGIS.Mobile.Workflow"                       xmlns:views="clr-namespace:VertiGIS.Mobile.Toolkit.Views;assembly=VertiGIS.Mobile.Toolkit"                       x:Class="App1.Workflow.CustomFormElement">    <Label Text="I'm a custom form element"/></core:ContentComponent>
App1/App1/workflow/CustomFormElement.xaml.cs
namespace App1.Workflow{    [XamlCompilation(XamlCompilationOptions.Compile)]    public partial class CustomFormElement : ContentComponent    {        public CustomFormElement(Geocortex.Workflow.Runtime.Definition.Forms.Element element, string name)            : base(element, name)        {            InitializeComponent();        }    }}

Registering Form Elements#

Form Elements must be registered through a custom workflow activity that extends RegisterCustomFormElementBase.

App1/App1/workflow/RegisterComponent.cs
[assembly: Export(typeof(RegisterCustomFormElements))]namespace App1.Workflow{    class RegisterCustomFormElements : RegisterCustomFormElementBase    {        public const string Action = "CustomFormElement";
        public override Task<IDictionary<string, object>> Execute(IDictionary<string, object> inputs, IActivityContext context)        {            Register("CustomFormElement", typeof(CustomFormElement), context);            return Task.FromResult((IDictionary<string, object>)new Dictionary<string, object>());        }    }}

Using Form Elements#

Custom form elements can be used in a form through the special "custom" form element. This form element displays custom form elements by referencing them by the id they were registered with.

important

Custom form elements will only be available to a workflow if the form element registration activity is run beforehand. It's best practice to run the form element registration activity at the start of a workflow.

Raising Form Events#

VertiGIS Studio Workflow form elements can raise events. A custom form element can also raise events, including a custom event type.

Events are raised through the OnEventRaised method of the form component. The following custom form element demonstrates how various form events can be raised.

App1/App1/workflow/CustomFormComponent.xaml
<?xml version="1.0" encoding="UTF-8"?><core:ContentComponent  xmlns:core="clr-namespace:VertiGIS.Mobile.Workflow.Core;assembly=VertiGIS.Mobile.Workflow"                        xmlns="http://xamarin.com/schemas/2014/forms"                        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"                        xmlns:views="clr-namespace:VertiGIS.Mobile.Toolkit.Views;assembly=VertiGIS.Mobile.Toolkit"                        x:Class="App1.Workflow.CustomFormComponent">    <StackLayout>        <views:EnhancedButton Text="Raise Clicked Event" Clicked="RaiseClickedEvent"/>        <views:EnhancedButton Text="Raise Changed Event" Clicked="RaiseChangedEvent"/>        <views:EnhancedButton Text="Raise Custom Event" Clicked="RaiseCustomEvent"/>    </StackLayout></core:ContentComponent>
App1/App1/workflow/CustomFormComponent.xaml.cs
namespace App1.Workflow{    [XamlCompilation(XamlCompilationOptions.Compile)]    public partial class CustomFormComponent : ContentComponent    {        public CustomFormComponent(Geocortex.Workflow.Runtime.Definition.Forms.Element element, string name)            : base(element, name)        {            InitializeComponent();        }
        private void RaiseClickedEvent(object sender, EventArgs e)        {            RaiseEvent(new Event()            {                Type = Event.CLICKED            });        }
        private void RaiseChangedEvent(object sender, EventArgs e)        {            RaiseEvent(new Event()            {                Type = Event.CHANGED            });        }
        private void RaiseCustomEvent(object sender, EventArgs e)        {            RaiseEvent(new Event()            {                Type = Event.CUSTOM,                Argument = "Custom Argument"            });        }    }}

Access Properties of Custom Form Elements#

A custom form element may produce a value that a workflow needs to access at runtime. You can set a property on the this.Element object to expose that value to the form.

App1/App1/workflow/CustomFormComponent.xaml
<?xml version="1.0" encoding="UTF-8"?><core:ContentComponent  xmlns:core="clr-namespace:VertiGIS.Mobile.Workflow.Core;assembly=VertiGIS.Mobile.Workflow"                        xmlns="http://xamarin.com/schemas/2014/forms"                        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"                        xmlns:views="clr-namespace:VertiGIS.Mobile.Toolkit.Views;assembly=VertiGIS.Mobile.Toolkit"                        x:Class="App1.Workflow.CustomFormComponent">    <StackLayout>        <Label>            <Label.FormattedText>                <FormattedString>                    <Span Text="This form element has a value of: "/>                    <Span Text="{Binding Element.Value}"/>                </FormattedString>            </Label.FormattedText>        </Label>    </StackLayout></core:ContentComponent>
App1/App1/workflow/CustomFormComponent.xaml.cs
namespace App1.Workflow{    [XamlCompilation(XamlCompilationOptions.Compile)]    public partial class CustomFormComponent : ContentComponent    {        public CustomFormComponent(Geocortex.Workflow.Runtime.Definition.Forms.Element element, string name)            : base(element, name)        {            BindingContext = this;            Element.Value = 42;            InitializeComponent();        }    }}

You can then use the Get Form Element Property activity to access the Value property, along with other properties supported by custom form elements.