dotnet/maui
在 GitHub 查看Add ConverterCulture property on Binding to allow overriding of culture settings
Open
#5,696 创建于 2022年3月31日
area-xamlgood first issueproposal/opent/a11y
仓库指标
- Star
- (23,245 star)
- PR 合并指标
- (平均合并 47天 9小时) (30 天内合并 248 个 PR)
描述
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.