Forum Xamarin.Forms

Static (Centralized) Resources


I'm trying to create some application wise styles, defined in App.xaml.

I've used this guide to create the App.XAML

In App.Xaml I've added my style:




Then I've added a new content page and made it my MainPage.

In the XAML of my newly created MainPage I've added a label in order for using my style:

But when running it I get an exception "StaticResource not found for key textColor"

What am I doing wrong. Can any one please make a simple POC project for me?

I have attatched my demo project.


  • Gigex42Gigex42 USMember ✭✭✭✭
    edited July 2016

    Well just writing pink in there wont do the job :smile:

    You have to define what type of resource it is, the name and value.

    <Application.Resources> <ResourceDictionary> <Color x:Key="NAME">VALUE</Color> </ResourceDictionary> </Application.Resources>

    In your page you can access it by

    <Grid BackgroundColor={StaticResource NAME}>

  • Hi Daniel

    I forgot to format my code as Code, sot the side ate most of it. But that was exactly what I did. And still I get the exception.

  • Gigex42Gigex42 USMember ✭✭✭✭
    edited July 2016

    Could you post your code again from you page and app.xaml?

  • App.xaml

        <?xml version="1.0" encoding="utf-8" ?>
        <Application xmlns=""
              <Style x:Key="CustomStyle" TargetType="Label" BaseResourceKey="SubtitleStyle">
                <Setter Property="Label.TextColor" Value="Color.Pink"/>


    using Xamarin.Forms;

    namespace App22
        public partial class App : Application
            public App()
                MainPage = new Page1();


    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns=""
      <StackLayout Padding="0,20,0,0">
        <Label Text="TESTING 1 - 2- - 3 - 4 " FontSize="Medium" FontAttributes = "Bold" Style= "{StaticResource CustomStyle}" />

    I've been Googeling a lot and some says that I have to call InitializeComponent(); in App.xaml.cs but that won't compile.

  • Gigex42Gigex42 USMember ✭✭✭✭

    public App() { InitializeComponent(); MainPage = new NavigationPage(new LoginPage()); }

    And in your app.xaml you write
    <Setter Property="Label.TextColor" Value="Color.Pink"/>

    You can delete the 'Label.' and 'Color.'

  • GOT IT!!!!
    x:Class="..." was wrong s it wasn't linked together with it's cs file

    THANK YOU for your time

Sign In or Register to comment.