Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format WPF Listview Column to show 2 only decimal points.

How can I format a WPF Listview Column to show 2 only decimal points?

like image 517
Sauron Avatar asked Oct 08 '09 08:10

Sauron


2 Answers

Assuming you are talking about a GridViewColumn within a ListView: if you are using .net3.5 SP1 you can use the StringFormat property of your column's Binding;

e.g.

<ListView ItemsSource="{StaticResource MyData}">
  <ListView.View>
    <GridView>
      <GridViewColumn DisplayMemberBinding="{Binding Path=Description}"/>
      <GridViewColumn DisplayMemberBinding="{Binding Path=Price, StringFormat=Now only {0:#.00}!}"/>
    </GridView>
  </ListView.View>
</ListView>

If you're not on SP1 yet, then a Converter would be the way forward...

like image 169
kiwipom Avatar answered Oct 11 '22 00:10

kiwipom


According to this (Link no longer works)

The simplest way is:

<TextBlock Text="{Binding StringFormat={}{0:00.00}}" />
like image 38
Junaid Qadir Shekhanzai Avatar answered Oct 11 '22 00:10

Junaid Qadir Shekhanzai