Step 4 - Create interactions

In this step you learn how to use the Node Components window to create interactions in your application using triggers and actions.

Create interactions using triggers and actions

Use triggers and actions to create interactions. Use triggers to set off actions, such as setting a property to a certain value or setting the state of an application.

In Kanzi Studio you add and set triggers and actions in the Node Components window.

You can find the Node Components window in the same group as the Properties window.

../../_images/add-on-attached-trigger.png

In this section you create a button and use triggers and actions to write a message to the Log window.

To create interactions using triggers and actions:

  1. In the Node Tree window press Alt and right-click the RootPage node, select Button 2D, and name it Next.

    Most of the Kanzi nodes set only the node layout and functionality. This gives you the flexibility to make nodes look the way you want them to look.

    The content that you place in the RootPage node is visible in the whole application. For example, if you want to make the top-level navigation visible in your whole application, create it in the RootPage node.

    ../../_images/project-next.png
  2. In the Preview click image0 to enter the Analyze mode, right-click image1, and select Borders of 2D nodes.

    Use the Analyze mode in the Preview window to inspect the structure and performance of your application.

    Borders of 2D nodes outlines the borders of 2D nodes with striped lines.

    For example, this allows you to see 2D nodes that do not have a visual representation. The Button 2D node you created in the previous step is in the top-left corner of the Preview window.

    ../../_images/preview-debug-border-of-2d.png
  3. In the Node Tree window select the Next node, in the Node Components window in the Button: Click message trigger press Alt and right-click Actions, and select Write Log.

    Use the Write Log action to print a message to the Log window.

    ../../_images/project-next.png ../../_images/triggers-write-log.png
  4. In the Write Log action next to the Log Text property click Enter Operation and select <Name>.

    Use the <Name> macro to print to the Log window the type of the node which contains this action.

    ../../_images/write-log-settings.png
  5. In the main menu select Window > Log to open the Log window.

    Kanzi prints to the Log window messages, warnings, and errors.

    ../../_images/window-log.png ../../_images/log-window.png

In the Preview window when you click the area of the Next Button 2D node, you set off the Button: Click trigger that executes the Write Log action, which in turn writes the name of the node to the Log window.

Create navigation buttons using the Preview window tools

In this section you define the look of the button you created in the previous section and add an action so that you can use it as a navigation button in the application.

To create navigation buttons using the Preview window tools:

  1. In the Node Tree press Alt and right-click the Next node and select Image.

    You use this Image node to define the look and size of the button.

    ../../_images/project-next-image.png
  2. In the Properties window set the Image property to the Arrow image.

    When you add nodes to a Button 2D node, by default the Button 2D node inherits the size of its child nodes.

    ../../_images/properties-image-arrow.png
  3. In the Preview window position the Next button:

    1. In the Preview window use the Node tool node-tool, right-click the arrow Image node and in the context menu select Select > Next to select the Next node.

      The Preview window can be either in Edit or Interact mode:

      • In the Edit mode you can use the Preview window to edit the content in your project. Select any of the Preview window tools preview-node-tool grid-tool text-tool image3 image4 image5 to enter the Edit mode.

      • In the Interact mode you can interact with your application in the Preview window as you would on a device. When you are using a Preview tool, to switch to the Interact mode, in the Preview window click interact.

      ../../_images/project-next-image.png ../../_images/preview-node-tool-select-next.png
    2. In the Node tool node-tool align tool align click the middle-right square to align the node to the right and center of the RootPage node, its parent node.

      ../../_images/preview-node-tool-align.png
  4. In the Node Components press Alt and right-click the Button: Click trigger, and select Dispatch Message Action > Page Host > Navigate to Next.

    Use the Navigate to Next action to go to the next Page or Page Host node of the node that you set in this action.

    ../../_images/triggers-navigate-to-next1.png
  5. In the Navigate to Next action set the Target Item to the RootPage node.

    When the Button: Click trigger executes this action, the action navigates to the next Page node of the RootPage node.

    ../../_images/navigate-to-next-settings.png
  6. In the Node Tree window select the Next node and press the Ctrl D keys to duplicate the node.

    You duplicate and modify the Next node to create a button to navigate to the previous Page node of the RootPage node.

    ../../_images/project-duplicate-next.png
  7. In the Node Tree window press the F2 key and rename the node to Previous.

    ../../_images/project-previous.png
  8. In the Preview window use the Node tool node-tool to position the Previous button:

    • In the Node tool node-tool align tool align click the middle-left square to align the node to the left and center of the RootPage node, its parent node.

      ../../_images/preview-node-tool-align-previous.png
    • In the Preview window move the mouse pointer to the outer side of the node handles and rotate the node by 180 degrees to make it point towards the left.

      Tip

      When you use the Node tool node, move the mouse pointer over the center of the node handles to resize the node node-tool-resize, and to the outer side of the handles to rotate the node node-tool-rotate. When rotating hold down the Shift key to rotate a node in 45 degree increments.

      ../../_images/preview-node-tool-align-previous-rotate.png
  9. In the Node Components window right-click the Navigate to Next action and select Delete.

    ../../_images/triggers-remove-action.png
  10. In the Node Components press Alt and right-click the Button: Click trigger, select Dispatch Message Action > Page Host > Navigate to Previous, and in the Navigate to Previous action set the Target Item to the RootPage node.

    ../../_images/triggers-navigate-to-previous.png ../../_images/navigate-to-previous-settings.png
  11. In the Preview window click image8 and image9 to exit the Edit and Analyze modes.

    ../../_images/preview-exit-edit-debug-modes.png

In the Preview window when you click the Next and Previous buttons, you set off the Button: Click triggers in these buttons and use the Navigate to Next and Navigate to Previous actions to go to the next and previous Page child nodes of the RootPage node.

../../_images/getting-started-step-4.gif

< Previous step | Next step >

See also

To learn more about creating buttons, complete Tutorial: Creating a button.

To learn more about the Write Log action, see Using Write Log action.

To learn more about triggers and actions, see Triggers.

To learn more about the Preview window tools, see Editing your application in the Preview.