6

i read that i can use data converters in binding like ...

<TextBlock Text="{Binding Converter={StaticResource PositionConverter}}" />

from here

but i wonder if there are any "in-built" converters. because creating converters to just output say 2 decimal places etc seem troublesome. i just thought that there must be sometime inbuilt that i can use?

Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
  • Not a list of built-in converters, but since .NET 3.5 there is also a FormatString property on the binding class, which can be used for simple formating (e.g. 2 decimal places) – JPW Sep 04 '10 at 10:37

2 Answers2

9

Here is the list of all converters provided by the framework

Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
  • +1 Nice. Are they already instantiated at any point with a known (and stable) resource-key so that they can be used without declaring them newly in xaml? – HCL Sep 04 '10 at 09:45
  • I don't think so, but I guess you can instantiate them in app.xaml once and have them available in whole app. – Matěj Zábský Sep 04 '10 at 09:46
  • @commanderz: Yes, this is also more reliable in case of the keys will be changed in further versions of the fcl. Thanks. – HCL Sep 04 '10 at 09:53
6

For a list of built-in converters, see commanderz's answer

creating converters to just output say 2 decimal places etc seem troublesome

Indeed, and you don't need to ;)

Instead, you can use the StringFormat property to specify a format specifier:

<TextBlock Text="{Binding SomeValue, StringFormat=F2}" />

See this page for details on formatting and lists of valid format specifiers.

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758