WindowsCommunityToolkit
WindowsCommunityToolkit copied to clipboard
Use of CultureInfo in StringFormatConverter
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
?
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 🙌
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?
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 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?
Hi, I'm willing to work on it.
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.
@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 ?