Skip to content

App.xaml resources defined in an inner ResourceDictionary are ignored #1237

Closed

Description

@jeromelaban

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

Given The following XAML:

<Application
    x:Class="HomeControl.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Application.Resources>
        <ResourceDictionary>
            <SolidColorBrush x:Key="SystemControlBackgroundBaseLowBrush" Color="#3f3f40"/>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Current behavior

The SystemControlBackgroundBaseLowBrush resource cannot be found.

Expected behavior

The SystemControlBackgroundBaseLowBrush resource can be used.

Workaround

Not defining an explicit ResourceDictionary allows for resources to be recognized.

Environment

Package Version(s): 1.45

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • Windows
  • Build tasks

Visual Studio

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

Activity

  1. added
    kind/bug
    platform/wasm 🌐
    platform/android 🤖
    platform/ios 🍎
    on Jul 15, 2019
  2. NGame1 commented on Jul 29, 2019

    @NGame1

    Any upcomming fix for this issue?

  3. jeromelaban commented on Jul 29, 2019

    @jeromelaban
    MemberAuthor

    Does the workaround help in your context ?

  4. NGame1 commented on Jul 29, 2019

    @NGame1

    Yes if it has any other workaround instead of copy-pasting resources in every page and control.

  5. jeromelaban commented on Jul 29, 2019

    @jeromelaban
    MemberAuthor

    The issue here is the ResourceDictionary node, if you remove it and place the content directly under the <App.Resources> it should be enough.

  6. NGame1 commented on Jul 29, 2019

    @NGame1

    Ah, I got it but I think it should not work for me. because I have Theme based resource dictionaries.

  7. jeromelaban commented on Jul 29, 2019

    @jeromelaban
    MemberAuthor

    I see. Then another workaround is to move the resources in a separate file. That way you'll get the same behavior.

  8. NGame1 commented on Jul 29, 2019

    @NGame1
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Styles/Generic.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    

    I tried this both in Application.Resources and Page one none of them worked, unfortunately.

  9. jeromelaban commented on Jul 29, 2019

    @jeromelaban
    MemberAuthor

    Then it may be related to the style you're trying to apply. I fail to remember if you had a sample for the specific code ?

  10. NGame1 commented on Jul 29, 2019

    @NGame1

    App.xaml

        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/Styles/Generic.xaml"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    

    Styles/Generic.xaml

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:HomeControlApp.Shared.Styles">
    
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Dark">
                <SolidColorBrush x:Key="HomeControlPageBackgroundThemeBrush" Color="#F1F1F1"/>
            </ResourceDictionary>
    
            <ResourceDictionary x:Key="Light">
                <SolidColorBrush x:Key="HomeControlPageBackgroundThemeBrush" Color="#F1F1F1"/>
            </ResourceDictionary>
    
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
    

    MainPage

    
        <Grid Background="{StaticResource HomeControlPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="100"/>
            </Grid.RowDefinitions>
    
            <Grid Grid.Row="0">
                <TextBlock Text="Home Control" Style="{StaticResource DefaultTextBlockStyle}" VerticalAlignment="Center" FontSize="24" Margin="12,0" FontWeight="SemiBold"/>
            </Grid>
            
        </Grid>
    
  11. jeromelaban commented on Jul 29, 2019

    @jeromelaban
    MemberAuthor

    Ah I see. The issue may be in the theme resources then. Does defining HomeControlPageBackgroundThemeBrush outside of the theme dictionaries, as a standard StaticResource work ?

  12. NGame1 commented on Jul 29, 2019

    @NGame1

    No it doesn't.
    HomeControlApp.zip

  13. NGame1 commented on Jul 31, 2019

    @NGame1

    Did you able to find any workaround?

  14. self-assigned this
    on Aug 23, 2019
  15. jeromelaban commented on Oct 11, 2019

    @jeromelaban
    MemberAuthor

    Thanks for the repro @NGame1 ! Since your report, we made a few other changes, including the support for ThemeResources, and along with #1818, the scenario should now be working properly.

    Just note that until #1766 passes, overriding platform defined styles is not yet possible. If you define your own resources, it will work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugplatform/android 🤖platform/ios 🍎platform/wasm 🌐

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions