dotnet/maui

Add ConverterCulture property on Binding to allow overriding of culture settings

Open

#5,696 opened on Mar 31, 2022

View on GitHub
 (6 comments) (6 reactions) (1 assignee)C# (1,951 forks)batch import
area-xamlgood first issueproposal/opent/a11y

Repository metrics

Stars
 (23,245 stars)
PR merge metrics
 (Avg merge 47d 9h) (248 merged PRs in 30d)

Description

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.

Contributor guide