pickermauitextcolor

MAUI UserAppTheme settings not apply to Picker/Searchbar


Environment: VS 17.4 preview 1, Windows10, System Theme : Dark

To reproduce the bug:

1, Create a new Maui program.

2, added a line

        Application.Current.UserAppTheme = AppTheme.Light;

to App.xaml.cs file

3, in mainpage.xaml, build a picker and a searchbar like this:

    <StackLayout>
        <Border Stroke="Red">
            <Picker>
                <Picker.ItemsSource>
                    <x:Array Type="{x:Type x:String}">
                        <x:String>Item1</x:String>
                        <x:String>Item2</x:String>
                        <x:String>Item3</x:String>
                    </x:Array>
                </Picker.ItemsSource>
            </Picker>
        </Border>
        <Border Stroke="Blue">
            <SearchBar WidthRequest="300"
                       HeightRequest="50"
                       Placeholder="input search text"
                       TextColor="Blue" />
        </Border>
    </StackLayout>

4, Make sure your system is in Dark theme.

5, Start the program.

you can see, the picker is still in dark panel; if you move mouse over the picker, the text color is changed to WHITE, looks like it disappeared. The searchbar button is disappeared because it's white.


Solution

  • UPDATE: Added fix for windows and android.

    For Windows
    Set the RequestedTheme property in Platforms > Windows > App.xaml to 'Light' or 'Dark'.
    Remember to set the Application.Current.UserAppTheme = AppTheme.Light; as well for your app along with the below cha

    <maui:MauiWinUIApplication
        x:Class="NetMaui.WinUI.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:maui="using:Microsoft.Maui"
        RequestedTheme="Light"
        xmlns:local="using:NetMaui.WinUI">
    
    </maui:MauiWinUIApplication>
    

    For Android
    I've made a video, which might be what you're after. Had the same issue. This code needs to go in your MainApplication.cs under Android platform folder.

    AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
    

    https://youtu.be/7Rqq8LrdkO8