Referencing Xamarin Application Resources from Code

144 Views Asked by At

I have an app.xaml that looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Foo.App">
    <Application.Resources>
        <!-- Application resource dictionary -->
        <Color x:Key="MyRed">#ad1929</Color>
    </Application.Resources>
</Application>

If I try to reference one of my colours like so:

var myRed = (Color)Application.Current.Resources["MyRed"];

I get an exception:

System.Collections.Generic.KeyNotFoundException: The resource 'MyRed' is not present in the dictionary.

Is it something to do with trying to reference the resource from a different project?

Can't work out where I'm going wrong...

0

There are 0 best solutions below