Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select not working with CultureInfo en-GB on .NET MAUI blazor hybrid #2066

Closed
bpsc-wkubis opened this issue May 17, 2024 · 2 comments
Closed
Labels
closed:done Work is finished

Comments

@bpsc-wkubis
Copy link

馃悰 Bug Report

I am attempting to implement FluentSelect as a culture picker in my Blazor Hybrid Maui application. Previously, I utilized an HTML select, which functioned correctly in all scenarios

@page "/"
@using System.Globalization


<h1>@Resources.Resource1.HelloWorld</h1>


<strong>Culture:</strong>
<select @bind="Culture">
    @foreach (var culture in cultures)
    {
        <option value="@culture">@culture.DisplayName</option>
    }
</select>

@code
{
    CultureInfo[] cultures = new[]
    {
        new CultureInfo("en-GB"),
        new CultureInfo("pl-PL")
    };

    CultureInfo Culture
    {
        get => CultureInfo.CurrentCulture;
        set
        {
            if (CultureInfo.CurrentCulture != value)
            {
                Thread.CurrentThread.CurrentCulture = value;
                Thread.CurrentThread.CurrentUICulture = value;
                CultureInfo.DefaultThreadCurrentCulture = value;
                CultureInfo.DefaultThreadCurrentUICulture = value;
            }
        }
    }
}

However, when I replace the HTML select with FluentUI select, I encounter issues when one of the available cultures is set to "en-GB". It appears as though the FluentUI select is caught in an infinite loop within the setter of the Culture property, when I switch the culture to "en-US", the FluentUI select operates as expected.

@page "/"
@using System.Globalization


<h1>@Resources.Resource1.HelloWorld</h1>

<FluentSelect 
    Items="@cultures" 
    @bind-SelectedOption="Culture">
</FluentSelect>

@code
{
    CultureInfo[] cultures = new[]
    {
        new CultureInfo("en-GB"), // Only breaks on en-GB - en-US works fine
        new CultureInfo("pl-PL")
    };

    CultureInfo Culture
    {
        get => CultureInfo.CurrentCulture;
        set
        {
            if (CultureInfo.CurrentCulture != value)
            {
                Thread.CurrentThread.CurrentCulture = value;
                Thread.CurrentThread.CurrentUICulture = value;
                CultureInfo.DefaultThreadCurrentCulture = value;
                CultureInfo.DefaultThreadCurrentUICulture = value;
            }
        }
    }
}

馃捇 Repro or Code Sample

https://github.com/bpsc-wkubis/maui-fluentui-broken-select-with-cultureinfo

馃 Expected Behavior

Select works fine with all Cultures

馃槸 Current Behavior

Select breaks on

馃拋 Possible Solution

馃敠 Context

Implement Culture selector based on FluentSelect.

馃實 Your Environment

  • OS & Device: [Windows] on [PC]
  • Browser []
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.4 and 4.7.2]
@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label May 17, 2024
@dvoituron
Copy link
Collaborator

It's strange, but it doesn't seem to come from a particular culture, but from the lack of "Default Culture" in the list of proposals. Is this possible?

In any case, adding CultureInfo.CurrentCulture works for me.

CultureInfo[] cultures = new[]
{
    CultureInfo.CurrentCulture, // 馃憟
    new CultureInfo("en-GB"), 
    new CultureInfo("pl-PL"),
};

@bpsc-wkubis
Copy link
Author

Thank for feedback, this workaround is sufficient for me, I will leave it up to you if you wanna change this behavior or leave it as it is.

@vnbaaij vnbaaij added closed:done Work is finished and removed triage New issue. Needs to be looked at labels May 20, 2024
@vnbaaij vnbaaij closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:done Work is finished
Projects
None yet
Development

No branches or pull requests

3 participants