开发者

Format WPF Listview Column to show 2 only decimal points.

开发者 https://www.devze.com 2022-12-08 04:19 出处:网络
How can I format a WPF Listview Column to show 2 onl开发者_如何学Goy decimal points?Assuming you are talking about a GridViewColumn within a ListView: if you are using .net3.5 SP1 you can use the Stri

How can I format a WPF Listview Column to show 2 onl开发者_如何学Goy decimal points?


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...


According to this (Link no longer works)

The simplest way is:

<TextBlock Text="{Binding StringFormat={}{0:00.00}}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消