Skip to content

ThemeResource bindings in ResourceDictionary not re-evaluated on runtime changes #3644

Closed

Description

@MartinZikmund

Current behavior

Consider the following XAML:

<Grid Background="{ThemeResource MyBrush}" />

And the following ResourceDictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
					xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <ResourceDictionary.ThemeDictionaries>
      <ResourceDictionary x:Key="Light">
         <Color x:Key="MyColor">#FFFFFF</Color>
      </ResourceDictionary>
      <ResourceDictionary x:Key="Dark">
         <Color x:Key="MyColor">#000000</Color>
      </ResourceDictionary>
   </ResourceDictionary.ThemeResources>
   <SolidColorBrush x:Key="MyBrush" Color="{ThemeResource MyColor}" />
</ResourceDictionary>

When the application first loads, the "MyBrush" resource gets evaluated and its value reflecting the application's initial theme is stored in _values field in ResourceDictionary.cs.

When theme changes at runtime (caused by application theme change or element-level theme change), the values don't get re-evaluated, so calling TryGetValue with a different theme will just return the "obsolete" value (on this line).

Expected behavior

The requested theme should apply to the resources with ThemeBinding as well.

How to reproduce it (as minimally and precisely as possible)

See above.

Environment

Nuget Package: latest

Package Version(s): latest

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Windows
  • Build tasks
  • Solution Templates

Visual Studio:

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Activity

  1. added
    kind/bug
    triage/untriaged
    project/styling 👔
    and removed
    triage/untriaged
    on Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/bugproject/styling 👔

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions