You scored ${score} of ${total}. It replaces each placeholder with the value of a matching argument. Each argument is a Number or a String, and you can bind its value to a view model property.
Store the template in a view model String property so you can change it at runtime. This helps with localization, because each language can put the values in a different order.
Creating a string template
1
Create the template property
Add a String property to your view model and set its value to
You scored ${score} of ${total}. Add Number properties for score and total.2
Create the converter
In the Data panel, click the
+ button and select Converter > String > Template.3
Add arguments
Next to Arguments, click the Add Argument (
+) button and choose Number or String. Add one argument for each value you want to insert. For this example, add two Number arguments.4
Name and bind each argument
Name the arguments
score and total. Bind each argument’s value to the matching view model property.5
Apply the converter
Bind your text to the String property that holds the template, and set Converter to your string template.
- Template:
You scored ${score} of ${total} - Arguments:
score(Number) bound to a property with the value10, andtotal(Number) bound to a property with the value12
Placeholders
A placeholder can refer to an argument by name, by position, or by order.
The Inspector shows each argument’s position next to its name. Drag an argument to change its position.
An argument name can use letters, digits, and
_, and can’t start with a digit. If two arguments have the same name, a placeholder uses the first one.
A placeholder with no matching argument adds nothing to the text.
Formatting numbers
Add a colon and a printf-style format after the placeholder name to control how a Number argument is displayed.
Without a format, numbers show up to 6 decimal places, with trailing zeros removed. The
, flag adds thousands separators. Integer formats such as %d round the number. If the format is not valid, the number uses the default format.
String arguments ignore the format.
Choosing a syntax
Use Syntax to choose how placeholders are written:${name}(default){name}{{name}}- Custom: set your own Open and Close delimiters. Each delimiter is 1 to 4 ASCII symbols, such as
{,%, or<. It can’t include_,\, or:.
\${score} displays ${score} instead of the value. Two backslashes display one backslash.