Merge pull request #259 from sandermvanvliet/patch-1

Document StringFormat parameter of Binding
This commit is contained in:
Max Katz 2022-05-18 21:48:53 -04:00 коммит произвёл GitHub
Родитель 79a2a60c9b 9742021358
Коммит 310e37b572
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 23 добавлений и 0 удалений

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

@ -58,3 +58,26 @@ The available binding modes are:
The `Default` mode is assumed if one is not specified. This mode is generally `OneWay` for control properties that do not change due to user input \(e.g. `TextBlock.Text`\) and `TwoWay` for control properties that _do_ change due to user input \(e.g. `TextBox.Text`\).
## String Formatting <a id="binding-stringformat"></a>
You can apply a format string to the binding to influence how the value is represented in the UI:
```markup
<TextBlock Text="{Binding FloatValue, StringFormat=\{0.0\}}" />
```
When a `StringFormat` parameter is present, the value of the binding will be converted using the `StringFormatValueConverter` which will be passed the format string.
The format string is specified slightly different than in WPF, note the additional escaped curly braces:
**WPF:**
```markup
<TextBlock Text="{Binding FloatValue, StringFormat=0.0}" />
```
**Avalonia:**
```markup
<TextBlock Text="{Binding FloatValue, StringFormat=\{0.0\}}" />
```