Reputation: 8116
I've got a double, for example
double d = 4.323d;
And I want to display it in a TextBlock on a Silverlight 4 application, but the display should be this:
4.32
And I cannot change the StringFormat on the binding whatsoever.
The exception is that if the number is this:
double d2 = 4d;
Then it should display
4
, not 4.00
.
And the worst exception is that it should take in account the current UI culture, which implies that if the app is deployed in the US it should use a .
as a decimal seperator, and in Europe it should use a ,
(well not in the UK, but you get the point...)
I could set the defaultformat to #.##
IF I were able to change the StringFormat, but I want to do it through CultureInfo
Upvotes: 2
Views: 764
Reputation: 189457
I'm going to assume for the moment that you believe you can't use StringFormat in binding because it doesn't use CultureInfo
. That being the case add these two usings to your user control code behind :-
using System.Windows.Markup;
using System.Threading;
and then add this to its constructor:-
Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);
Now a binding with StringFormat=#.##
will use the appropriate decimal separator for the current culture.
Upvotes: 5