WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

Use of CultureInfo in StringFormatConverter

Open hansmbakker opened this issue 4 years ago • 7 comments

I'm trying to use the StringFormatConverter.

String formatting is often linked to a certain CultureInfo (numbers, dates, currency, etc). For my case I would like to format a double into a currency string.

I see no way how to specify the CultureInfo as a parameter to this StringFormatConverter; the language parameter of the converter is not used.

My workaround would be to perform the formatting not in XAML, but I believe that defeats the purpose of this converter.

Is there a way to specify CultureInfo in StringFormatConverter?

hansmbakker avatar Apr 20 '20 12:04 hansmbakker

Hello hansmbakker, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Apr 20 '20 12:04 ghost

Hi @hansmbakker, it does look like we don't expose this parameter, you could add a property on the converter so it could be configured and make a PR.

In the meantime, you may be able to just call sys:String.Format directly in x:Bind?

michael-hawker avatar Apr 20 '20 18:04 michael-hawker

Given that the meaning of the ConverterLanguage / language parameter is up for interpretation by the converter, would you then agree that the ConverterLanguage parameter could be directly mapped to a culture name that is supplied to a CultureInfo constructor?

hansmbakker avatar Apr 20 '20 19:04 hansmbakker

@hansmbakker that's an interesting solution. It makes sense to me! 🙂

We could also do both, so if you want the culture info to be the same everywhere you can set it on the Converter's property in the resources, and otherwise you can do one-off on the binding with the ConverterLanguage or to override whatever default you've set?

michael-hawker avatar Apr 21 '20 17:04 michael-hawker

Hi, I'm willing to work on it.

tutkus avatar Apr 24 '22 17:04 tutkus

Thanks @tutkus, I've assigned this to you. Feel free to ask any questions if you need assistance, and otherwise open up a PR. Note we're in a bit of a transition period, so not sure when we may get to new things, but I think this seems pretty well-scoped and simple, so should be easy to migrate as needed with our plans.

There's info in the Wiki about building and getting started with the Toolkit, if you haven't looked there already.

michael-hawker avatar Apr 25 '22 23:04 michael-hawker

@hansmbakker - all good, I managed to built the code and started looking into it. I assume once I will have this issue fixed, the PR should be sent to master branch, right ?

tutkus avatar Apr 26 '22 06:04 tutkus