8

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 Answers2

6

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"
       .../>

  • Although Intellisense says "the attachable property 'IsLegacyColorModeEnabled' was not found in type 'VisualElement'.", this solved my problem! Thank you! – jnel899 Jun 12 '20 at 15:20
  • It works, but in my view a better solution is to change the TextColor using a custom Renderer. (That's what I did). – Kolky Apr 07 '21 at 14:17
  • I also confirm this. Thank you so much. – unobatbayar Mar 17 '22 at 07:36
1

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

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • 1
    Hi, thanks for your answer. We were already doing this bit to disable Dark Mode. It had something to do with LegacyColorManagement (see extensive answer above). The only part I still don't understand is why the defaultColor is still the one of the device InterfaceStyle and not the one declared in our Info.Plist – Brent Van Vosselen Feb 20 '20 at 13:04
  • Oh so that was the case, I was thinking from another tangent altogether anyway thanks for letting me know what was actually the issue – FreakyAli Feb 20 '20 at 13:15