xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] DynamicResource not updating when reordering ResourceDictionary in App.xaml #6795

Open NickeManarin opened 5 years ago

NickeManarin commented 5 years ago

Description

My app supports Light and Dark themes. I implemented the option to change the theme by having two resource dictionaries in separated files, like so:

When the user changes the theme to Light, I simply move the Light ResourceDictionary to the last position.

The problem is that this only works for pages opened afterwards. It does not update the DynamicResources from pages already opened.

Steps to Reproduce

  1. Download/Clone the project.
  2. Run on Android.
  3. Click on the button "Open Test Page" to open a page with DynamicResource set.
  4. Click on "Change resource" to change the theme to dark.
  5. Notice that the MainPage still has light theme, but opening the test page results in a dark theme.

Expected Behavior

DynamicResource should be updated when the resource dictionary changes. Even for pages already open and loaded, like what happens with WPF.

Actual Behavior

DynamicResources are not updated, they act like StaticResources.

Basic Information

Reproduction Link

https://github.com/NickeManarin/Xamarin.Demos

(I'm using the same project to showcase bugs for other projects too, so ignore the first two buttons)

Edit:

It also happens in iOS, latest version. But I don't remember if the demo project is set up to run the iOS version of the app or not.

jsuarezruiz commented 5 years ago

Thanks for the sample!. I have been doing some tests and I can reproduce the problem. The situation is having two ResourceDictionaries at the same time and just change the order. Doing this only affects to pages opened afterwards.

Meanwhile, you can have this working with small changes. Add only the default theme (for example, the Light one) in the resources of App.

When you want to change the theme, delete the added Resource and add the new one.

6795

Xamarin.Demos.zip

NickeManarin commented 5 years ago

Any news in a fix for this bug?

NickeManarin commented 5 years ago

@jsuarezruiz This would be way harder for me to control my app, there's several styles and localizations, with fallback for generic ones (pt_BR -> pt).