!--a11y-->
Creating the Context for the
TreeView 
Before you create the context for the TreeView, you must decide which data you want to display in the tree. This includes visible data, for example the text of a node, and invisible data, for example, whether a node can be selected.
The objective of this example application is to display a file structure in a tree and display the name of the selected file. This means that you need an attribute in the context in which the currently selected name is stored and can be displayed. Several context attributes are required for the nodes of the tree. The application requirements are as follows:
· Each node must be labeled.
· A file must have a different icon to a folder
· A file is a leaf and can therefore have no further leaves or nodes
· One node must already be opened
· Selecting a file must trigger an event that displays the name of the file on the screen; selecting a folder must not trigger an event.
This results in several context attributes that you create in the TreeView context.
The TreeView is already contained in the template.
1. To open the View Designer, double-click TreeView in the project structure.
2. Choose the Context tab page.
3. Create the nodes and attributes displayed in the table below and set the properties.
Context Element |
Type |
Properties |
Value |
|
Value node |
|
|
|
Recursion Node |
TreeView.FolderContent |
|
|
Value attribute |
type |
|
|
Value attribute |
type |
|
|
Value attribute |
type |
|
|
Value attribute |
type |
|
|
Value attribute |
type |
|
|
Value attribute |
type |

The tree UI-element represents a hierarchy as it is saved in the context. If the tree is not recursive, then the entire desired structure in the context must be displayed with the help of context-nodes and context-attributes. In doing so, bear in mind that the child nodes possess the singleton-property false. Thereby it is achieved that there exist a child node instance for every node element in the parent node.
If the singleton-property was true, only one single node instance would be represented, whose content would change every time the lead-selection of the parent node changed. Thus, the context for the unselected node elements would not contain child nodes, so that in the tree-UI-element there would be no data displayed at the unselected places.
4.
To save the
project metadata, choose
Save all metadata from the
toolbar.
The FolderContent context element later displays a folder or a file in the tree of the TreeView. The name of the folder or the file is saved in the Text attribute. The HasChildren attribute specifies whether the context-node displays a node or a leaf. You can use this attribute to set the IconSource to a folder icon or file icon. The IsExpanded attribute is required to expand a node initially. You use the IgnoreAction attribute to define whether or not the event onAction is triggered when this node is selected.
The recursive ChildNode node links to the FolderContent, which can thus be nested as deeply as you like.
The TreeView context is defined and its file structure can be nested as deeply as is required. It also has the corresponding properties for displaying the tree as requested.