7
votes

I seem to have some troubles with the TextColor of my Entry on iOS when Dark Mode is enabled. Whenever I set the Entry's Enabled state to false, the TextColor turns white and it's not possible to change. I used the following simple code to reproduce this.

Page.xaml

    <Entry x:Name="TestEntry" />
Page.xaml.cs

    public OnboardingPage()
    {
        InitializeComponent();

        TestEntry.Text = "Testo";
        TestEntry.TextColor = Color.Blue;
        TestEntry.IsEnabled = false;
    }

I am currently using the latest version of Xamarin.Forms. (4.4.0.991640)

Does anybody have an idea what's going wrong here? I don't think this is expected behavior..

Thanks in advance!

2

2 Answers

5
votes

In the meanwhile I have found the fix necessary to my question.

Apparently the EntryRenderer on iOS uses uses the default color when legacy color management is enabled and the Entry is disabled. Setting the legacyColorManagement to False on the Entry solves this issue.

XF check for legacycolormanagement https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Extensions/VisualElementExtensions.cs#L15

XF check for TextColor of the Entry https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs#L272

I've added following code to my *Page.xaml and now the colors are rendering correctly:

*Page.xaml

<ContentPage xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
             ...>

<Entry ios:VisualElement.IsLegacyColorModeEnabled="False"
       .../>

1
votes

The reason that is happening because of how iOS works with the dark mode for you to handle this you have to add the following in your Info.Plist

<key>UIUserInterfaceStyle</key>
<string>Light</string>

What this will do is stop your app from changing anything when Dark mode is turned on i.e. it is sort of an opt-out

Goodluck

Feel free to get back if you have questions