Merge pull request #351 from vikkio88/master

adding a more detailed example of escaping binding
This commit is contained in:
Max Katz 2022-10-13 11:42:09 -04:00 коммит произвёл GitHub
Родитель 559f4aaa26 9a00304054
Коммит 0fb5d888a9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 4 добавлений и 1 удалений

Просмотреть файл

@ -72,11 +72,13 @@ You can apply a format string to the binding to influence how the value is repre
<!-- Option 3: If the string format does not start with {0}, you don't need to escape the string format. -->
<!-- Note: If you have a whitespace in your string format, surround it with single quotes '' -->
<TextBlock Text="{Binding Animals.Count, StringFormat='I have {0} animals.'}" />
<!-- Note: You need to escape the curly braces in case your format string starts with the value you are binding, like so: -->
<TextBlock Text="{Binding Animals.Count, StringFormat='{}{0} animals live in the farm.'}" />
```
When a `StringFormat` parameter is present, the value of the binding will be converted using the `StringFormatValueConverter` which will be passed the format string.
Other than in WPF, you need to surround the string format with curly braces and start with 0: (`{0:TheStringFormat}`). If the curly braces are at the beginning of the format string, you need to escape them by either adding `{}` in front of it or by using backslashes `\{ ... \}`:
Other than in WPF, you need to surround the string format with curly braces and start with 0: (`{0:TheStringFormat}`). If the curly braces are at the beginning of the format string, even if sorrounded by single quotes, you need to escape them by either adding `{}` in front of it or by using backslashes `\{ ... \}`:
**WPF:**
@ -89,6 +91,7 @@ Other than in WPF, you need to surround the string format with curly braces and
```markup
<TextBlock Text="{Binding FloatValue, StringFormat={}{0:0.0}}" />
<TextBlock Text="{Binding FloatValue, StringFormat=\{0:0.0\}}" />
<TextBlock Text="{Binding FloatValue, StringFormat='{}{0:0.0}'}" />
```
{% hint style="info" %}