After upgrading Xamarin.Forms Nuget from 4.6.0-sr3 to 4.6.0-sr4, my solution does not compile any more. The problem is that I am overriding _OnRequestedThemeChanged_ on a page to redraw something manually when the theme is changed. This method seems to be removed. Also _AppThemeColor_ seems to be missing. I use it to retrieve the current color from the resource dictionary in code:
C#
var primaryColor = (AppThemeColor)App.Current.Resources["PrimaryColor"];
It is all right that things changes. App themes support is experimental after all and I am really looking forward to test the new ability for setting the theme according to the user preferences. I was however surprised when looked into the documentation that I found nothing about these breaking changes. I think that the Wiki page for API changes in 4.6.0-sr4 should mention them! Look at the page (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/4.6/4.6.0-api) and try Ctrl+F to find something about the removed _OnRequestedThemeChanged_ or _AppThemeColor_ . There is nothing.
By the way, the page documents API changes in 4.6.0-sr4 but compared to which version? I though I will find there changes compared to 4.6.0-sr3, but it is more likely there are only changes compared to 4.5.0. Which of its Service Versions? There are more of them.
Yep, you're right! We generate the API changes by comparing between major versions (e.g., 4.5.0 compared to 4.6.0), so changes within the 4.6.0 series are hard to follow here. We don't generally allow breaking API changes to occur in service releases, but experimental API is subject to change at any time. You can sort of find the changes if you go through https://docs.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/4.6/4.6.0-sr4#dark-modeapp-themes, but I agree--we should have done a better job of documenting this, especially since the instructions at the top of the release notes are no longer correct!
Sorry about that! We'll get an update published for the release notes soon.
Which of its Service Versions? There are more of them.
We compare to the latest published service release at the time the notes are generated. We should probably put that version in the notes, too!
We also have great docs here that should already be updated with the changes: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/system-theme-changes
Release notes are updated and point to the current documentation.
Can I ask why AppThemeColor was dropped - as the new way with AppThemeBinding is a real pain to use comparatively.
Hi,
I have update to the latest version form the version 4.6.0.847 and the AppThemeColor is gone.
I need to convert this code in my resources.xaml otherwise my application doesn't compile:
<AppThemeColor x:Key="Tema_Bianco" Light="{StaticResource Bianco}" Dark="{StaticResource Bianco}" />
<AppThemeColor x:Key="Tema_Nero" Light="{StaticResource Nero}" Dark="{StaticResource Nero}" />
<AppThemeColor x:Key="Tema_ShellHeaderFooter" Light="{StaticResource GrigioChiaro}" Dark="{StaticResource GrigioChiaro}" />
<AppThemeColor x:Key="Tema_Testo" Light="{StaticResource Nero}" Dark="{StaticResource Nero}" />
<AppThemeColor x:Key="Tema_ModaliFooter" Light="{StaticResource Bianco}" Dark="{StaticResource Bianco}" />
<AppThemeColor x:Key="Tema_ButtonDisabled" Light="{StaticResource Nero}" Dark="{StaticResource Nero}"/>
Anyone can help me?
Where I can find a guide to do this?
Thank you.
@Raystorm7 I have a temporary workaround that works for me (at least on android) - you can see my code in https://github.com/xamarin/Xamarin.Forms/issues/10973#issuecomment-651689715
Simply add the code and a quick find/replace for AppThemeColor to theme:AppThemeColor and you are good to go.
YMMV
@Raystorm7 I have a temporary workaround that works for me (at least on android) - you can see my code in #10973 (comment)
Simply add the code and a quick find/replace for AppThemeColor to theme:AppThemeColor and you are good to go.
YMMV
Hi,
thank you but when this code runs
var appThemeResources = resources.Where(kvp => kvp.Value is IAppThemeResource).ToList();
the appThemeResources
is empty.
Thank you.
@Raystorm7 I have this working in my project so I am not sure of your exact issue. Are you calling this after initializeInitializeComponent();
? Basically it should scan the merged dictionary for items that derive from IAppThemeResource and split them appropriately into multiple resources then rip out the apptheme resources and switch in whichever set matches the current theme (detecting theme changes). Make sure you have changed the XAML to <theme:AppThemeColor x:Key="PageBackgroundColor" Light="Blue" Dark="Red" Default="Green" />
so that you are definitely using the AppThemeColor that derives from IAppThemeResource
.
Most helpful comment
Can I ask why AppThemeColor was dropped - as the new way with AppThemeBinding is a real pain to use comparatively.