Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ListView Thousand Separator

I want to display numbers i thousand separated format. Numbers are displayed in a Column of ListView control. I've the following xaml code, but it doesn't even compile!

<GridViewColumn Header="Total" DisplayMemberBinding="{Binding PaidValue, StringFormat={0:0,0}}" />

From my c# point of view, {0:0,0} is a correct format to do this, right? What is wrong with this?

The error is totally unrelated : "Unknown build error, 'Key Can not be null' pointing to the same line of xaml code. If tried other variants of the same format with no use.

like image 252
Hadi Eskandari Avatar asked Sep 02 '26 06:09

Hadi Eskandari


2 Answers

OKay, I found a way to do this. I need to say that, in fact I DO have SP1 installed, so as a lot of blog posts are implying {0:c} should work, while it does not and will end up producing the same compile-time error! Here's how I did it:


<GridViewColumn DisplayMemberBinding="{Binding Path=PaidValue, StringFormat='0,0'}" />

Compiles and works with no problem. I wonder if other binding's StringFormat values are still valid.

like image 80
Hadi Eskandari Avatar answered Sep 05 '26 06:09

Hadi Eskandari


<GridViewColumn Header="Total" 
DisplayMemberBinding="{Binding PaidValue, StringFormat={0:c}}" />

Will format the number to the native string currency.

You can find more numeric formats from this site

like image 25
Tawani Avatar answered Sep 05 '26 04:09

Tawani