Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve a value from ResourceDictionary in code behind

I have a Windows 10 universal app with a few resource dictionaries for styles and such. In one such resource dictionary, I have a color, MyBlue that I want to access via the code behind. How is this achieved?

I've tried this.Resources["MyBlue"], but since MyBlue is defined in a separate resource dictionary and not directly in the page resources it doesn't exist in this collection.

Here's my app.xaml:

<Application.Resources>

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles/PodStyles.xaml"/>
            <ResourceDictionary Source="Styles/ButtonStyles.xaml"/>
            <ResourceDictionary Source="Styles/OfferStyles.xaml"/>
            <ResourceDictionary Source="Styles/MyStyles.xaml"/>

            <ResourceDictionary>
                <!--Global View Model Locator-->
                <vm:ViewModelLocator x:Key="Locator"
                                     d:IsDataSource="True"/>
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>
like image 278
earthling Avatar asked Dec 19 '22 22:12

earthling


1 Answers

Have you tried

Application.Current.Resources["MyBlue"]
like image 114
Igor Ralic Avatar answered Dec 28 '22 10:12

Igor Ralic