Home > Net >  How to override resource to another resource using key in XAML?
How to override resource to another resource using key in XAML?

Time:12-30

First of all, I'm sorry for my poor English.

I want to change code below:

    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Default">
                    <AcrylicBrush
                        x:Key="NavigationViewExpandedPaneBackground"
                        BackgroundSource="HostBackdrop" 
                        TintColor="{ThemeResource SystemChromeAltHighColor}" 
                        TintOpacity="0.6" 
                        FallbackColor="{ThemeResource SystemChromeMediumColor}" />
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrast">
                    <SolidColorBrush
                        x:Key="NavigationViewExpandedPaneBackground"
                        Color="{ThemeResource SystemColorWindowColor}"  />
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
        </ResourceDictionary>
    </Page.Resources>

to like this:

    <Page.Resources>
        <??? 
            x:key="NavigationViewExpandedPaneBackground" 
            ???="{ThemeResource SystemControlChromeMediumAcrylicWindowMediumBrush}"
    </Page.Resources>

I have tried Setter, Style, ... but all failed. How to implement what I want?

CodePudding user response:

For your scenario, you could use StaticResource to convert above code.

<StaticResource x:Key="NavigationViewExpandedPaneBackground" ResourceKey="SystemControlChromeMediumAcrylicWindowMediumBrush"/>

For more detail please refer to StaticResource docuemnt .

  • Related