I have some WPF text blocks on the stack that I want to bind and format.
eg. the following formats: 24h date format without a second part:
<TextBlock Text="{Binding MyCustomObject, StringFormat={}{0:HH:mm}}" />
Now I would like to bind an integer and also display the + and - sign (e.g. +6 or -4).
<TextBlock Text="{Binding MyOtherCustomObject, StringFormat={}{0:+#}}" />
This, however, does not work. Is this possible or do I need to write a complete converter just for this?
EDIT
Nicholas's message led me to the answer:
<TextBlock Text="{Binding MyOtherCustomObject, StringFormat={}{0:+#;-#;''}}" />
Basically you provide a format for positive numbers, negative numbers and an optional part of what to do with zero. In this case, I indicated that zero should be displayed as an empty string.
Hi,
Michelle
source share