dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Regression from MAUI 8: Picker entries blank in release mode (Android) #25935

Open BioTurboNick opened 2 hours ago

BioTurboNick commented 2 hours ago

Description

I have a Picker that is populated by an array of values. They are mapped to a localized string through a ValueConverter.

Since updating to MAUI 9, the picker is now full of blank entries in release mode.

Steps to Reproduce

XAML:

<ContentView.Resources>
    <ResourceDictionary>
        <vc:IntToPowerConverter x:Key="intToPower" />
    </ResourceDictionary>
</ContentView.Resources>

<Picker Grid.Column="2"
        FontSize="16"
        VerticalTextAlignment="End"
        ItemDisplayBinding="{Binding Converter={StaticResource intToPower}}">
    <Picker.ItemsSource>
        <x:Array Type="{x:Type x:Int32}">
            <x:Int32>0</x:Int32>
            <x:Int32>1</x:Int32>
            <x:Int32>2</x:Int32>
            <x:Int32>3</x:Int32>
            <x:Int32>4</x:Int32>
            <x:Int32>5</x:Int32>
            <x:Int32>6</x:Int32>
            <x:Int32>7</x:Int32>
            <x:Int32>8</x:Int32>
            <x:Int32>9</x:Int32>
        </x:Array>
    </Picker.ItemsSource>
</Picker>

C#:

static readonly char[] superscriptCharacters = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹', '⁻'];
static readonly char[] characters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-'];
static readonly Dictionary<char, char> superscriptDictionary = new(superscriptCharacters.Length);
const char times = '×';

public static string GetSuperscript(int exponentValue, CultureInfo culture)
{
    string formatedValue = exponentValue.ToString("D", culture);

    string formattedSuperscripts = string.Empty;

    for (int i = 0; i < formatedValue.Length; i++)
        formattedSuperscripts += superscriptDictionary[formatedValue[i]];

    return formattedSuperscripts;
}

public static string ToPowerOfTen(int value, CultureInfo culture)
{
    string formattedValue = string.Empty;

    if (value == 0) return formattedValue;

    formattedValue += times + 10.ToString(culture);

    if (value == 1) return formattedValue;

    formattedValue += GetSuperscript(value, culture);

    return formattedValue;
}

public class IntToPowerConverter :
    IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (targetType != typeof(string))
            return new object();

        return value switch
        {
            int intValue => FormatHelpers.ToPowerOfTen(intValue, culture),
            _            => string.Empty
        };
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
        throw new NotImplementedException();
}

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.92 SR9.2

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No response

Relevant log output

mattleibow commented 2 hours ago

@simonrozsival This is using ItemDisplayBinding and I know we touched that in .NET 9...

BioTurboNick commented 1 hour ago

FWIW I have confirmed that if I remove ItemDisplayBinding= the items show up.