Add ConverterCulture property on Binding to allow overriding of culture settings
#5696 aperta il 31 mar 2022
Metriche repository
- Star
- (23.245 star)
- Metriche merge PR
- (Merge medio 47g 9h) (248 PR mergiate in 30 g)
Descrizione
Description
This proposal was originally done for Forms.
This new functionality would add the ConverterCulture property for bindings, which allows the consumer to override the locale for a binding. This functionality is also available in WPF.
Public API Changes
Added properties:
public class Binding
{
// Default value would be `CurrentCulture` ideally or go to en-US.
// The latter is what WPF does, although I'm not sure why, `CurrentCulture` makes more sense in my mind
[System.ComponentModel.TypeConverter(typeof(CultureInfoIetfLanguageTagConverter))]
public System.Globalization.CultureInfo ConverterCulture { get; set; }
// Add an additional constructor to take the `ConverterCulture` parameter or create an overload for it
// Existing Binding code here
}
I think we need to add our own type converter class because the one in WPF/WinUI lives in System.Windows which won't be ideal?
// TypeConverter to make sure we can convert values like en-US and nl-NL
// to a `CultureInfo` object through XAML.
// E.g.: <Label Text="{Binding MyText, ConverterCulture='nl-NL'} />"
public class CultureInfoIetfLanguageTagConverter
{
// Code to transform string into `CultureInfo`
}
Intended Use-Case
I don't have a concrete example in mind. The proposal on the Forms repo has been upvoted a couple of times, I guess it can be useful in multi-language, multi-locale scenarios where you want to override something.