StringFormat in XAML, WPF : Currency Formatting

2020-07-11 04:36发布

问题:

How can i obtain currency formatting according to my country i.e indian rupee, INR or Rs ??

Please tell me the way to achieve this ?? Right now when i use StringFormat="{}{0:C}", "$" is being used

I have gone through this link and i am able to achieve the desired result but i am worried about using this in my project. Is this code safe ??

What does this line mean in the above link "when you test functionality related to settings change it’s important you start the program directly from a folder window, if you run it from within Visual Studio or any other program you may get incorrect results."

回答1:

You can specify the culture in your binding like this:

TextBlock Text="{Binding Value, StringFormat=C, ConverterCulture=nl-BE}" 

nl-BE is belgian culture, you can exchange it with Indian culture info, I don't know that ;-)



回答2:

Or you can set your current thread to the right culture, so you will use it everywhere in your application:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("hi-IN");