Theme doesn't change correctly in maui for elements with no background when the system theme is black

1.8k views Asked by At

When changing the theme of the OS, the application normally does not display all entries. I tried to change the background of the entry, but then the frames are not visible on iOS, and if it is empty (without a placeholder), then it will be extremely difficult to find it. Added Application.Current.UserAppTheme = AppTheme.Light to the App.xaml.cs file.

Screenshot.

The problem is present on both iOS and Android.

2

There are 2 answers

1
KoMa On BEST ANSWER

As it turned out, the problem is that I use a custom entry in which I do not specify a background color, after setting it to Transparent, the entry is displayed normally, except that there is no frame around (ios) and underlining (android). So far I just wrapped the record in a border and it works.

I'll leave the question open for now, maybe someone will find a more elegant solution to the problem

Update: I stumbled upon this article and after trying this method, I no longer met the dark theme https://learn.microsoft.com/en-us/answers/questions/231994/disable-dark-mode-in-xamarin-forms-4-8

3
Liqun Shen-MSFT On

An easy way to respond to system theme change is use AppThemeBinding markup extension.

<Entry BackgroundColor="{AppThemeBinding Light=Green, Dark=Yellow}"/>

or you may use Style:

<Style TargetType="Entry" x:Key="EntryStyle">
    <Setter Property="BackgroundColor"
            Value="{AppThemeBinding Light={StaticResource LightNavigationBarColor}, Dark={StaticResource DarkNavigationBarColor}}" />
</Style>

For more info, you could refer to Respond to system theme changes