question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Page.BackgroundColor and others not reacting to changes in Application.Current.UserAppTheme

See original GitHub issue

Description

Some things are not updated properly when the UserAppTheme is changed, most notably the Page.BackgroundColor. There are also other things with the same issue, such as the view that pops up when you want to select something from a picker.

This issue is probably related to #6092

Steps to Reproduce

  1. Create a new .MAUI project
  2. Add this to MainPage.xaml
      <Picker HorizontalOptions="Center"
              x:Name="picker">
        <Picker.ItemsSource>
          <x:Array Type="{x:Type x:String}">
            <x:String>Just</x:String>
            <x:String>some</x:String>
            <x:String>random</x:String>
            <x:String>text</x:String>
          </x:Array>
        </Picker.ItemsSource>
      </Picker>
  1. Change the implementation of OnCounterClicked in MainPage.xaml.cs to this:
  private void OnCounterClicked(object sender, EventArgs e)
  {
    if (picker.SelectedIndex < 0)
    {
      picker.SelectedIndex = 0;
    }

    Button button = (Button)sender;
    switch (Application.Current.UserAppTheme)
    {
      case AppTheme.Unspecified:
        Application.Current.UserAppTheme = AppTheme.Light;
        button.Text = "Light";
        break;

      case AppTheme.Light:
        Application.Current.UserAppTheme = AppTheme.Dark;
        button.Text = "Dark";
        break;

      case AppTheme.Dark:
        Application.Current.UserAppTheme = AppTheme.Unspecified;
        button.Text = "Unspecified";
        break;
    }
  }
  1. Click on the button to switch through themes. After a theme switch, select something from the picker.

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

Windows 10, Android 12, Android 7

Did you find any workaround?

No response

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
daletmancommented, Dec 3, 2022

Does work for me on macOS with iOS, Android and MacCatalyst in VS when using the code from the issue, but doesn’t work when the OS does change the Theme.

My VS info:

Visual Studio Community 2022 for Mac Preview
Version 17.5 Preview (17.5 build 437)
Installation UUID: d9252da1-331a-46f1-b7b3-e50626c0b00e

Runtime
.NET 7.0.0 (64-bit)
Architecture: X64

Roslyn (Language Service)
4.4.0-3.22461.4+8ab250290a4010c11a21521f78dbc87dbb7aac81

NuGet
Version: 6.3.1.1

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/7.0.100/Sdks
SDK Versions:
	7.0.100
	6.0.403
MSBuild SDKs: /Applications/Visual Studio (Preview).app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	7.0.0
	6.0.11
	6.0.10

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin Designer
Version: 17.5.1.13
Hash: 14bdde937f
Branch: remotes/origin/d17-5
Build date: 2022-11-02 21:36:45 UTC

Apple Developer Tools
Xcode 14.1 (21534.1)
Build 14B47b

Xamarin.Mac
Version: 8.12.0.2 (Visual Studio Community)
Hash: 87f98a75e
Branch: d17-3
Build date: 2022-07-25 20:18:54-0400

Xamarin.iOS
Version: 16.0.0.72 (Visual Studio Community)
Hash: 6756a1146
Branch: release/6.0.4xx-xcode14
Build date: 2022-09-21 08:51:06-0400

Xamarin.Android
Version: 13.1.0.1 (Visual Studio Community)
Commit: xamarin-android/d17-4/13ba222
Android SDK: /Users/home/Library/Android/sdk
	Supported Android versions:
		12.0 (API level 31)
		8.1  (API level 27)
		11.0 (API level 30)
		7.1  (API level 25)
		13.0 (API level 33)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 33.0.3
SDK Build Tools Version: 32.1.0 rc1

Build Information: 
Mono: a96bde9
Java.Interop: xamarin/java.interop/d17-4@fcc33ce2
SQLite: xamarin/sqlite/3.39.3@23e1ae7
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.5.0.8
Hash: 6f27afd
Branch: remotes/origin/HEAD
Build date: 2022-11-02 21:36:49 UTC

Android Device Manager
Version: 0.0.0.1217
Hash: 6175224
Branch: main
Build date: 2022-11-02 21:36:49 UTC

Build Information
Release ID: 1705000437
Git revision: a5d0fb913c1ff781c80fe725a3e0511c34e26a08
Build date: 2022-11-02 21:34:21+00
Build branch: release-17.5
Build lane: release-17.5

Operating System
Mac OS X 12.6.1
Darwin 21.6.0 Darwin Kernel Version 21.6.0
    Thu Sep 29 20:12:57 PDT 2022
    root:xnu-8020.240.7~1/RELEASE_X86_64 x86_64

0reactions
msftbot[bot]commented, Feb 20, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Respond to system theme changes - .NET MAUI
NET MAUI app can respond to operating system theme changes by using the AppThemeBinding markup extension, and the SetAppThemeColor and ...
Read more >
Respond to system theme changes in Xamarin.Forms ...
Xamarin.Forms applications can respond to operating system theme changes by using the OnAppTheme type, and the DynamicResource markup ...
Read more >
Statusbar theme only changes after restarting app
My apps statusbar does not seem to react to android system theme changes while the app is loaded. The statusbar only updates after...
Read more >
Dynamic App Themes in Xamarin.Forms - YouTube
WT.mc_id=friends-0000-jamont * App Theme Bindings ... They are NOT officially affiliated or endorsed by Microsoft (my employer) in any way.
Read more >
Implement dark theme
On this page; Support dark theme in your app. Themes and styles; Change themes in-app. Force Dark. Disable Force Dark on a view....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found