The Great Escape

... and other cautionary tales

As with xaml, string literals can be enclosed within 'single quotes' or "double quotes" with appropriate use of xml escape-sequences.

Commas

If your expression string has commas in it, you must hide them from the xaml parser, otherwise z:Bind etc. will be given an incomplete string and things won't work as expected.

You can do this by enclosing the string inside quotes, like this:

Something="{z:Bind 'SomeFunction(param1, param2)'}"

or this

Something="{z:Bind \"SomeFunction(param1, param2)\"}"

and so on

Strings

If your expression string has string literals in it, you must 'escape' them, otherwise z:Bind etc. will be given an incorrect string and things won't work as expected. For example:

"{z:Bind Status == \'Administrator\'}"

or this

"{z:Bind Status == '\'Administrator\''}"

and so on

Long form

If your expression is getting bogged down in escape-sequences and commas and quotes, or if that's just the way you roll, you can use the long-form of expressing a z:Bind expression:

<Label Text="{z:Bind '\'Score: \'+ Count + \' points\''}"

becomes

<Label>
    <Label.Text>
        <z:Bind>
            'Score: '+ Count + ' points'
        </z:Bind>
    </Label.Text>
</Label>

Last updated