You can apply a named style from StylesInModel to a ViewModel UI element by using the Styles OCL/EAL operator in that element's Style Expression.
Purpose
Use Styles when you have defined a style in StylesInModel and want a Row, Column, Control, or placing container in a ViewModel to use it.
For example, if the Style Editor contains a style named Search, use the following expression to retrieve and apply that style:
selfVM.Styles.Search
Syntax
selfVM.Styles.StyleName
| Part | Meaning |
|---|---|
selfVM
|
The current ViewModel instance. |
Styles
|
Access to the styles defined in StylesInModel. |
StyleName
|
The name of the style to retrieve from the Style Editor. Replace this part with the name of your style. |
Apply a style to a ViewModel element
- Define the style in StylesInModel by using the Style Editor. For this example, create or use a style named
Search. - Open the ViewModel Editor.
- Select the Row, Column, Control, or placing container that should use the style.
- Set its Style Expression to the expression that names the style:
selfVM.Styles.Search
- Save the ViewModel and render the UI. The selected element uses the properties defined by the
Searchstyle.
Example: reuse a search style
A ViewModel can use the same named style in more than one place. If Search is defined in StylesInModel, set the Style Expression on each relevant UI element to:
selfVM.Styles.Search
The expression returns the Style object named Search. The element where you set the Style Expression then renders according to that style's defined properties.
Notes
- The name after
selfVM.Styles.must identify a style defined in StylesInModel. - Use this expression in the Style Expression of the UI element that you want to style; it does not define the style itself.
- To apply a different named style, replace
Searchwith that style's name. For example, a style namedHeaderis referenced asselfVM.Styles.Header.
