Kanzi  3.9.5
Kanzi Studio API
TriggerNodeComponent Interface Reference

Configure triggers. More...

Public Member Functions

TriggerActionItem CreateAction ([NotNull] TriggerActionType actionType)
 Creates a trigger action. More...
 
TriggerConditionItem CreateCondition ()
 Creates a trigger condition. More...
 
TriggerConditionItem CreateCondition ([NotNull] TriggerConditionItem toClone)
 Creates a trigger condition by cloning an existing trigger condition. More...
 
bool DeleteAction ([NotNull] TriggerActionItem action)
 Deletes a trigger action. More...
 
bool DeleteCondition ([NotNull] TriggerConditionItem condition)
 Deletes a trigger condition. More...
 

Properties

IEnumerable< TriggerActionItemActions [get]
 Gets the actions in a trigger. More...
 
IEnumerable< TriggerConditionItemConditions [get]
 Gets the conditions in a trigger. More...
 
bool IsMessageTrigger [get]
 Gets whether the trigger is a message trigger. More...
 
Node MessageSource [get, set]
 Gets or sets the target item from which to intercept messages. More...
 
NodeReference< Node > RelativeMessageSource [get, set]
 
MessageRoutingModeEnum RoutingMode [get, set]
 Gets or sets the message routing mode: More...
 
bool SetHandled [get, set]
 Gets or sets the message handling mode: More...
 
MessageType TriggerMessageType [get]
 Gets the Trigger Message Type. More...
 

Detailed Description

Configure triggers.

You can use this interface to:

  • Configure trigger settings. You can set the message handling, routing mode, and message source of a trigger.
  • Create and delete trigger actions. An action is an outcome of a trigger. Kanzi has general actions, such as Set Property and Write Log, and message actions, that you can use to control a specific type of item, such as Go To State, or Navigate To Page.
  • Create and delete trigger conditions. Trigger conditions enable you to set which conditions must be met for the trigger to set off.
See also
NodeComponentHost, TriggerActionItem, TriggerConditionItem

Member Function Documentation

◆ CreateAction()

TriggerActionItem CreateAction ( [NotNull] TriggerActionType  actionType)

Creates a trigger action.

Parameters
actionType
Returns
The trigger action.
See also
TriggerActionItem

Examples

To create a Write Log action:

public void Execute(PluginCommandParameter parameter)
{
// Create a Button 2D node named Click in the RootPage node.
var buttonClick = studio.ActiveProject.CreateProjectItem<Button2D>(
"Click",
studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage"));
// Get the first Button: Click trigger in the Click button.
var clickTrigger = buttonClick.Triggers.First(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// Create a Write Log action in the Button: Click trigger.
var writeLogAction = clickTrigger.CreateAction(studio.ActiveProject.TriggerActionTypeLibrary.GetItemByName("Kanzi.WriteLogAction"));
// In the Write Log action set Log Text to "Button clicked".
writeLogAction.Set(Properties.WriteLogActionLogText, "Button clicked");
}

To create a Set Property action:

// This example creates a button with a Set Property action in the Button: Click trigger.
// When you click the button, the Set Property action sets the value of the Layout Width
// property in the parent node of the button.
public void Execute(PluginCommandParameter parameter)
{
// Create a Button 2D node named Resize in the RootPage node.
var buttonSetWidth = studio.ActiveProject.CreateProjectItem<Button2D>(
"Resize",
studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage"));
// Get the first Button: Click trigger in the Resize button.
var clickTrigger =
buttonSetWidth.Triggers.First(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// Create a Set Property action in the Button: Click trigger.
var setPropertyAction = clickTrigger.CreateAction(studio.ActiveProject.TriggerActionTypeLibrary.GetItemByName("Kanzi.SetPropertyAction"));
// Create a reference to the parent node of the Button 2D node.
ProjectItemReference<ExportedPropertyContainerItem> routingTarget = new NodeReference<Button2D>("..");
// In the Set Property action set the Target Item to the parent node of the Resize button.
// Target Item is the node to which you apply the action.
setPropertyAction.Set(Properties.MessageArgumentSetPropertyTargetItem, routingTarget);
// In the Set Property action set Target Property to Layout Width.
// Target Property is the property to which you apply the new value.
setPropertyAction.Set(Properties.MessageArgumentSetPropertyPropertyType, Properties.NodeWidth);
// In the Set Property action set Target Property Attribute to Whole property.
setPropertyAction.Set(
Properties.MessageArgumentSetPropertyPropertyAttribute,
AnimationTargetPropertyAttributeEnum.WHOLE_PROPERTY);
// In the Set Property action set Value From to Fixed value.
setPropertyAction.Set(Properties.MessageArgumentSetPropertySourceType, EventArgumentValueTypeEnum.FIXED);
// In the Set Property action set Property Value to 500.
setPropertyAction.Set(Properties.MessageArgumentSetPropertyPropertyValue.Name, 500.0f);
}

To create a dispatch message action:

// This example creates a state manager with a state that sets the background color of the RootPage node,
// and a button with a Go To State action in the first Button: Click trigger.
// When you click the button, the background color of the RootPage node changes.
public void Execute(PluginCommandParameter parameter)
{
// Get the State Managers library which stores the state managers used in a Kanzi Studio project.
var stateManagerLibrary = studio.ActiveProject.StateManagerLibrary;
// Create a state manager named My State Manager in the State Managers library.
var myStateManager = studio.ActiveProject.CreateProjectItem<StateManager>(
stateManagerLibrary.GenerateUniqueChildName("My State Manager"),
stateManagerLibrary);
// Create a state group named My State Group in the My State Manager state manager.
var myStateGroup = studio.ActiveProject.CreateProjectItem<StateGroup>(
myStateManager.GenerateUniqueChildName("My State Group"),
myStateManager);
// Create a state named My State in the My State Group state group.
var myState = studio.ActiveProject.CreateProjectItem<State>(
myStateGroup.GenerateUniqueChildName("My State"),
myStateGroup);
// Create a state object named RootPage in the My State state.
var myStateObject = studio.ActiveProject.CreateProjectItem<StateObject>(
myState.GenerateUniqueChildName("RootPage"),
myState);
// Get the Brushes library in the Library > Materials and Textures which stores all the Brushes
// in a Kanzi Studio project.
var brushLibrary = studio.ActiveProject.BrushLibrary;
// Create a Color Brush named Blue Brush in the Brushes Library.
var blueBrush =
studio.ActiveProject.CreateBrush(
brushLibrary.GenerateUniqueChildName("Blue Brush"),
brushLibrary,
BrushTypeEnum.COLOR);
// Create a blue color.
var blueColor = System.Windows.Media.Color.FromArgb(255, 0, 0, 255);
// Set the color of the Blue Brush brush to the blue color.
blueBrush.Set(blueBrush.PropertyTypes.ColorBrushColor, blueColor);
// Add and set the Background Brush in the RootPage state object to Blue Brush.
myStateObject.AddProperty(Properties.Node2DBackgroundBrush);
myStateObject.Set(Properties.Node2DBackgroundBrush.Name, blueBrush);
// Get the RootPage node in the Screens/Screen node.
var parentNode = studio.ActiveProject.GetProjectItem("Screens/Screen");
var rootPage = parentNode.GetChild<PageHost>("RootPage");
// Set the State Manager property of the RootPage node to MyStateManager.
rootPage.Set(Properties.NodeStateManager.Name, myStateManager);
// Create a Button 2D node named "Go Blue" in the RootPage node.
var goButton = studio.ActiveProject.CreateProjectItem<Button2D>(
"Go Blue",
rootPage);
// Create a Text Block 2D node in the Go Blue button.
var buttonLabel = studio.ActiveProject.CreateProjectItem<TextBlock2D>("Label", goButton);
// Set the Text property of the Text Block 2D node to Go Blue.
buttonLabel.Set(Properties.TextConceptText, "Go Blue");
// Get the first Button: Click trigger in the Go Blue button.
var clickTrigger =
goButton.Triggers.First(
trigger => trigger.Get(
Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// In the Button: Click trigger create a trigger action, and set:
// * Trigger Action Type to Dispatch Message Action
// * Message Type to Go To State
var goToStateAction = clickTrigger.CreateAction(studio.ActiveProject.TriggerActionTypeLibrary.GetItemByName("Kanzi.DispatchMessageAction"));
goToStateAction.DispatchMessageActionMessageType = studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.StateManager.GoToState");
// In the Go To State action set Target Item to the RootPage node.
goToStateAction.RoutingTarget = new NodeReference<PageHost>(rootPage);
// In the Go To State action set State to My State.
goToStateAction.Set(Properties.MessageArgumentStateManagerState.Name, "My State");
}

To create a dispatch message action and set the target item using a relative path:

public void Execute(PluginCommandParameter parameter)
{
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Create a Page node named Page1 in the RootPage node.
var page1 = studio.ActiveProject.CreateProjectItem<Page>(rootPage.GenerateUniqueChildName("Page1"), rootPage);
// Set the Default Subpage property of the RootPage node to the Page1 node.
rootPage.Set(Properties.PageHostDefaultSubPage.Name, "Page1");
// Create a Page node named Page2 in the RootPage node.
studio.ActiveProject.CreateProjectItem<Page>(rootPage.GenerateUniqueChildName("Page2"), rootPage);
// Create a Button 2D node named "Next" in the RootPage node.
var nextButton = studio.ActiveProject.CreateProjectItem<Button2D>("Next", rootPage);
// Create a Text Block 2D node named "Next page" in the Next button.
var buttonLabel = studio.ActiveProject.CreateProjectItem<TextBlock2D>("Next page", nextButton);
// In the Text Block 2D node set the Text property to Next page.
buttonLabel.Set(Properties.TextConceptText, "Next page");
// Get the first Button: Click trigger in the Next button.
var clickTrigger =
nextButton.Triggers.First(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// In the Button: Click trigger create a trigger action, and set:
// * Trigger Action Type to Dispatch Message Action
// * Message Type to Navigate To Page
var navigateToPageAction = clickTrigger.CreateAction(studio.ActiveProject.TriggerActionTypeLibrary.GetItemByName("Kanzi.DispatchMessageAction"));
navigateToPageAction.DispatchMessageActionMessageType = studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Page.Navigate");
// In the Navigate To Page action use a relative path to set Target Item to the Page2 node.
navigateToPageAction.RoutingTarget = new NodeReference<Page>("../Page2");
}

◆ CreateCondition() [1/2]

TriggerConditionItem CreateCondition ( )

Creates a trigger condition.

Trigger conditions enable you to set which conditions must be met for the trigger to set off.

Returns
The trigger condition.
See also
TriggerConditionItem

Examples

To create an empty trigger condition:

public void Execute(PluginCommandParameter parameter)
{
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Create a Button 2D node in the RootPage node.
var button =
studio.ActiveProject.CreateProjectItem<Button2D>(rootPage.GenerateUniqueChildName("Button 2D"), rootPage);
// Get the first Button: Click trigger in the Button 2D node.
var clickTrigger = button.Triggers.First(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// Create an empty trigger condition for the first Button: Click trigger in the Button 2D node.
var triggerCondition = clickTrigger.CreateCondition();
}

◆ CreateCondition() [2/2]

TriggerConditionItem CreateCondition ( [NotNull] TriggerConditionItem  toClone)

Creates a trigger condition by cloning an existing trigger condition.

Parameters
toCloneThe trigger condition that you want to clone to create a new trigger condition.
Returns
The trigger condition.
See also
TriggerConditionItem

Examples

To create a trigger condition by cloning an existing trigger condition:

public void Execute(PluginCommandParameter parameter)
{
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Create a Button 2D node in the RootPage node.
var button =
studio.ActiveProject.CreateProjectItem<Button2D>(rootPage.GenerateUniqueChildName("Button 2D"), rootPage);
// Get the first Button: Click trigger in the Button 2D node.
var clickTrigger = button.Triggers.First(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// Create an empty trigger condition for the first Button: Click trigger in the Button 2D node.
var triggerCondition = clickTrigger.CreateCondition();
// Create a trigger condition by cloning the empty trigger condition that you created.
clickTrigger.CreateCondition(triggerCondition);
}

◆ DeleteAction()

bool DeleteAction ( [NotNull] TriggerActionItem  action)

Deletes a trigger action.

Parameters
actionThe trigger action that you want to delete.
Returns
When it deletes the action successfully, true, otherwise false.

Examples

To delete a trigger action:

// To delete a trigger action you first have to get the trigger and the action, and then use the DeleteAction
// function to delete the action.
public void Execute(PluginCommandParameter parameter)
{
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Create a Button 2D node in the RootPage node.
var button =
studio.ActiveProject.CreateProjectItem<Button2D>(rootPage.GenerateUniqueChildName("Button 2D"), rootPage);
// Get the first Button: Click trigger in the Button 2D node.
var clickTrigger = button.Triggers.First(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// In the Button: Click trigger create a Write Log action.
var writeLogAction = clickTrigger.CreateAction(studio.ActiveProject.TriggerActionTypeLibrary.GetItemByName("Kanzi.WriteLogAction"));
// Use the DeleteAction function to delete the Write Log action.
clickTrigger.DeleteAction(writeLogAction);
}

◆ DeleteCondition()

bool DeleteCondition ( [NotNull] TriggerConditionItem  condition)

Deletes a trigger condition.

Parameters
conditionThe trigger condition that you want to delete.
Returns
When it deletes the condition successfully, true, otherwise false.

Examples

To delete a trigger condition:

public void Execute(PluginCommandParameter parameter)
{
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Create a Button 2D node in the RootPage node.
var button =
studio.ActiveProject.CreateProjectItem<Button2D>(rootPage.GenerateUniqueChildName("Button 2D"), rootPage);
// Get the first Button: Click trigger in the Button 2D node.
var clickTrigger = button.Triggers.First(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName("Message.Button.Click"));
// Create an empty trigger condition for the first Button: Click trigger in the Button 2D node.
var triggerCondition = clickTrigger.CreateCondition();
// Use the DeleteCondition function to delete the trigger condition.
clickTrigger.DeleteCondition(triggerCondition);
}

Property Documentation

◆ Actions

IEnumerable<TriggerActionItem> Actions
get

Gets the actions in a trigger.

◆ Conditions

IEnumerable<TriggerConditionItem> Conditions
get

Gets the conditions in a trigger.

◆ IsMessageTrigger

bool IsMessageTrigger
get

Gets whether the trigger is a message trigger.

◆ MessageSource

Node MessageSource
getset

Gets or sets the target item from which to intercept messages.

Use either MessageSource or RelativeMessageSource to set the specific target item from which to intercept messages.

Examples

To create a trigger and set the target item from which the trigger intercepts messages:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Create a Toggle Button Group 2D node in the RootPage node.
var toggleButtonGroup = studio.ActiveProject.CreateProjectItem<ToggleButtonGroup2D>(
rootPage.GenerateUniqueChildName("Toggle Button Group 2D"),
rootPage);
// Create a Stack Layout 2D node in the Toggle Button Group 2D node.
var stackLayout = studio.ActiveProject.CreateProjectItem<StackLayout2D>("Stack Layout 2D", toggleButtonGroup);
// Create two Toggle Button 2D nodes in the Toggle Button Group 2D node.
var toggleButton1 = studio.ActiveProject.CreateProjectItem<ToggleButton2D>("Toggle Button 1", stackLayout);
var toggleButton2 = studio.ActiveProject.CreateProjectItem<ToggleButton2D>("Toggle Button 2", stackLayout);
// Create a Toggle Button Group: Toggled trigger in the Toggle Button Group 2D node.
var toggledTrigger = toggleButtonGroup.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.MessageTrigger));
toggledTrigger.Set(Properties.TriggerMessageType, studio.ActiveProject.MessageTypeLibrary.GetItemByName(MessageTypeNames.MessageToggleButtonGroupConceptToggled));
// To set the Toggle Button Group: Toggled trigger to intercept messages only from Toggle Button 1,
// set the Message Source of the Toggle Button Group: Toggled trigger to Toggle Button 1.
toggledTrigger.MessageSource = toggleButton1;
}

◆ RelativeMessageSource

NodeReference<Node> RelativeMessageSource
getset

Gets or sets the relative path to the target item from which to intercept messages:

  • Reference to the target item to intercept messages from a specific target item
  • Null to intercept messages from all sources

Use either RelativeMessageSource or MessageSource to set the specific target item from which to intercept messages.

Examples

To create a trigger and set the relative target item from which the trigger intercepts messages:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Create a Toggle Button Group 2D node in the RootPage node.
var toggleButtonGroup = studio.ActiveProject.CreateProjectItem<ToggleButtonGroup2D>(
rootPage.GenerateUniqueChildName("Toggle Button Group 2D"),
rootPage);
// Create a Stack Layout 2D node in the Toggle Button Group 2D node.
var stackLayout = studio.ActiveProject.CreateProjectItem<StackLayout2D>("Stack Layout 2D", toggleButtonGroup);
// Create two Toggle Button 2D nodes in the Toggle Button Group 2D node.
studio.ActiveProject.CreateProjectItem<ToggleButton2D>("Toggle Button 1", stackLayout);
studio.ActiveProject.CreateProjectItem<ToggleButton2D>("Toggle Button 2", stackLayout);
// Create a Toggle Button Group: Toggled trigger in the Toggle Button Group 2D node.
var toggledTrigger = toggleButtonGroup.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.MessageTrigger));
toggledTrigger.Set(Properties.TriggerMessageType, studio.ActiveProject.MessageTypeLibrary.GetItemByName(MessageTypeNames.MessageToggleButtonGroupConceptToggled));
// Create a reference to the Toggle Button 1 node.
NodeReference<Node> relativeMessageSource = new NodeReference<Node>("Stack Layout 2D/Toggle Button 1");
// To set the Toggle Button Group: Toggled trigger to intercept messages only from Toggle Button 1,
// set the Relative Message Source of the Toggle Button Group: Toggled trigger to Toggle Button 1.
toggledTrigger.RelativeMessageSource = relativeMessageSource;
}

To create a trigger and set it to intercept messages from all sources:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Create a Toggle Button Group 2D node in the RootPage node.
var toggleButtonGroup = studio.ActiveProject.CreateProjectItem<ToggleButtonGroup2D>(
rootPage.GenerateUniqueChildName("Toggle Button Group 2D"),
rootPage);
// Create a Stack Layout 2D node in the Toggle Button Group 2D node.
var stackLayout = studio.ActiveProject.CreateProjectItem<StackLayout2D>("Stack Layout 2D", toggleButtonGroup);
// Create two Toggle Button 2D nodes in the Toggle Button Group 2D node.
studio.ActiveProject.CreateProjectItem<ToggleButton2D>("Toggle Button 1", stackLayout);
studio.ActiveProject.CreateProjectItem<ToggleButton2D>("Toggle Button 2", stackLayout);
// Create a Toggle Button Group: Toggled trigger in the Toggle Button Group 2D node.
var toggledTrigger = toggleButtonGroup.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.MessageTrigger));
toggledTrigger.Set(Properties.TriggerMessageType, studio.ActiveProject.MessageTypeLibrary.GetItemByName(MessageTypeNames.MessageToggleButtonGroupConceptToggled));
// To set the Toggle Button Group: Toggled trigger to intercept messages from all sources,
// set the Relative Message Source of the Toggle Button Group: Toggled trigger to <No Item>.
toggledTrigger.RelativeMessageSource = null;
}

◆ RoutingMode

MessageRoutingModeEnum RoutingMode
getset

Gets or sets the message routing mode:

  • TUNNELING to intercept only tunneling messages
  • BUBBLING to intercept only bubbling messages
  • TUNNELING_AND_BUBBLING to intercept tunneling and bubbling messages

◆ SetHandled

bool SetHandled
getset

Gets or sets the message handling mode:

  • TRUE to intercept and handle the message.The message stops here, and does not continue neither bubbling nor tunneling in the project tree.
  • FALSE to intercept the message, but let the message continue bubbling or tunneling in the project tree.

◆ TriggerMessageType

MessageType TriggerMessageType
get

Gets the Trigger Message Type.

See also
Project.TriggerActionTypeLibrary