dotnetdevcsharp
dotnetdevcsharp

Reputation: 3980

Xamrain Forms Resource dictionary not being reconized

Ok I had thought I had this fixed but it would appear not for example I have a resource dictionary such as the following Which is my global styles named file GloabalTheme.xaml

But I get the following usually that is caused by an incorrect name but In this case you see there is not

The name 'InitializeComponent' does not exist in the current context

<?xml version="1.0" encoding="UTF-8"?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    x:Class="wellbeingmaster.Styles.GlobalTheme"
                    >
    <Color x:Key="background">#FFF</Color>
    <Color x:Key="mainBackground">#FFF</Color>
    <Color x:Key="mainLabel">#111</Color>
    <Color x:Key="secondaryLabel">#666</Color>
    <Color x:Key="entryBackground">#EEE</Color>
    <Color x:Key="radioBackground">#999</Color>
    <Color x:Key="borderColor">#DDD</Color>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Styles/Global.xaml" />
    </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>

But When I Look at the cs file its not reconizing it correct it still needs the cs file to be able to reference in the code behind.

using System;
using System.Collections.Generic;
using Xamarin.Forms.Xaml;

using Xamarin.Forms;

namespace wellbeingmaster.Style
{
    public partial class GlobalTheme : ResourceDictionary
    {
        public GlobalTheme()
        {
            InitializeComponent();
        }
    }
}

Upvotes: 0

Views: 125

Answers (1)

pinedax
pinedax

Reputation: 9346

The problem seems to be with the namespace.

In the code behind you have: wellbeingmaster.Style while in the XAML you have wellbeingmaster.Styles.GlobalTheme (an extra "s" in the x:Class property).

Try renaming Styles to Style in the XAML or the other way around in the code.

<?xml version="1.0" encoding="UTF-8"?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    x:Class="wellbeingmaster.Style.GlobalTheme"
                    >
    <Color x:Key="background">#FFF</Color>
    <Color x:Key="mainBackground">#FFF</Color>
    <Color x:Key="mainLabel">#111</Color>
    <Color x:Key="secondaryLabel">#666</Color>
    <Color x:Key="entryBackground">#EEE</Color>
    <Color x:Key="radioBackground">#999</Color>
    <Color x:Key="borderColor">#DDD</Color>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Styles/Global.xaml" />
    </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>

Upvotes: 1

Related Questions