views:

114

answers:

1

I've a Decimal retail price property that I'm binding to a TextBox e.g. Text="{Binding Path=RetailPrice}". By default this displays with all 4 decimal places showing "0.0000".

I assume I can use the built in DecimalConverter to shorten this to 2 decimal places "0.00", but can't for the life of me figure out the Xaml markup for this.

Or, do I have the wrong end of the stick, and do I have to roll my own converter to do this?

Any and all help will be appreciated, thanks.

+2  A: 

I assume I can use the built in DecimalConverter to shorten this to 2 decimal places "0.00"

No, you can't : DecimalConverter is a TypeConverter, it doesn't implement IValueConverter and has no relation with WPF.

Instead, you could use the Binding's StringFormat property :

<TextBlock Text="{Binding RetailPrice, StringFormat=F2}"/>
Thomas Levesque
You're a gentleman sir and thank you very much, that was wrecking me head so it was :)
Binary Worrier
.Net 3.5 SP1 added StringFormat btw.
sixlettervariables