好的,我本以为我已经修复了这个问题,但似乎没有。例如,我有一个资源字典,比如下面的哪个是我的全局样式命名文件GloabalTheme.xaml
但我得到以下通常是由不正确的名称引起的,但在这种情况下,你会看到没有
名称"InitializeComponent"在当前上下文中不存在
<?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>
但当我看cs文件时,它没有重新配置它,它仍然需要cs文件能够在后面的代码中引用。
using System;
using System.Collections.Generic;
using Xamarin.Forms.Xaml;
using Xamarin.Forms;
namespace wellbeingmaster.Style
{
public partial class GlobalTheme : ResourceDictionary
{
public GlobalTheme()
{
InitializeComponent();
}
}
}
问题似乎出在命名空间上。
在后面的代码中有:wellbeingmaster.Style
,而在XAML中有wellbeingmaster.Styles.GlobalTheme
(x:Class属性中多了一个"s"(。
尝试在XAML中将Styles
重命名为Style
,或者在代码中以其他方式重命名。
<?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>