Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF binding replace zeros with blanks

Tags:

c#

wpf

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.

like image 714
Rod Avatar asked Sep 10 '26 04:09

Rod


1 Answers

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.

enter image description here

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);
like image 166
Marshal Avatar answered Sep 11 '26 16:09

Marshal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!