I have this WPF xaml binding element below:
<telerik:GridViewDataColumn DataMemberBinding="{Binding Value, StringFormat='0.00'}" />
If Value is 0, I would like it to display an empty string.
I've tried:
DataMemberBinding="{Binding TotalStops, StringFormat='{}{0:#.#0}'}"
But when Value is 0, it displays .00 instead of an empty string.
In WPF, StringFormat support the ";" section separator.
Try this:
DataMemberBinding="{Binding Value, StringFormat={}{0:#.#0;(0);''}}"
This example shows 3 value formats: positive, negative, and zero value formatting from left to right, separated by semi-colons.
The image reference from article by Muhammad Shujaat Siddiqi
This is just not limited to WPF, this can work with where ever a string format is used in general.
double x = 0.00;
x.ToString("#.#0;;A BIG ZERO");
Console.WriteLine(x);