NPadrutt
NPadrutt

Reputation: 4257

Xamarin Forms picker on ios in Release Mode does not show text

I have a Xamarin Forms Applikation with a picker in a page defined like this:

            <Picker ItemsSource="{Binding AvailableCultures}"
                    SelectedItem="{Binding SelectedCulture, Mode=TwoWay}"
                    ItemDisplayBinding="{Binding DisplayName}" />

The relevant parts in the viewmodel are:

    private CultureInfo selectedCulture = CultureHelper.CurrentCulture;

    public CultureInfo SelectedCulture
    {
        get => selectedCulture;
        set
        {
            if(value == null)
                return;
            if(selectedCulture == value)
                return;
            selectedCulture = value;
            settingsFacade.DefaultCulture = selectedCulture.Name;
            CultureHelper.CurrentCulture = selectedCulture;
            RaisePropertyChanged();
        }
    }

    public ObservableCollection<CultureInfo> AvailableCultures { get; }

    private async Task LoadAvailableCulturesAsync()
    {
        await dialogService.ShowLoadingDialogAsync();

        CultureInfo.GetCultures(CultureTypes.AllCultures).OrderBy(x => x.Name).ToList().ForEach(AvailableCultures.Add);
        SelectedCulture = AvailableCultures.First(x => x.Name == settingsFacade.DefaultCulture);

        await dialogService.HideLoadingDialogAsync();
    }

This works without issues on the simulator when I debug. It also works without problems on Android. But when I deploy the application on iOS the texts are empty.

enter image description here

I can scroll through them and select new ones and the value is changed. I thought it might be a problem with the binding, but it persists when I turn linking off completely. What can cause that?

Repository Link: https://github.com/MoneyFox/MoneyFox

Upvotes: 0

Views: 185

Answers (1)

Junior Jiang
Junior Jiang

Reputation: 12723

After testing between Debug and Release mode , we will see that DisplayName not shows in Release mode, however EnglishName always shows.

The Debug mode:

enter image description here

The Release mode:

enter image description here

Therefore, there is a workaround to make it works in Release mode.

Modify Xaml code of Picker with binding EnglishName for ItemDisplayBinding as follows:

<Picker x:Name="MyPicker"
    ItemsSource="{Binding AvailableCultures}"
        SelectedItem="{Binding SelectedCulture, Mode=TwoWay}"
        ItemDisplayBinding="{Binding EnglishName}" />

Upvotes: 1

Related Questions