Xamarin.forms: [Bug] DynamicResource not updating when reordering ResourceDictionary in App.xaml

Created on 5 Jul 2019  路  3Comments  路  Source: xamarin/Xamarin.Forms

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:

  • Light.xaml
  • Dark.xaml

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

  • Version with issue: 4.0.0.425677
  • Last known good version: n/a
  • IDE: Visual Studio for Windows.
  • Platform Target Frameworks:

    • iOS: Latest.

    • Android: Android Pie, 28.

    • UWP: Not tested.

  • Android Support Library Version: 28
  • Nuget Packages: See project.
  • Affected Devices: Nokia 6.1 plus.

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.

3 help wanted Android bug up-for-grabs

Most helpful comment

@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).

All 3 comments

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

Any news in a fix for this bug?

@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).

Was this page helpful?
0 / 5 - 0 ratings