Xamarin xaml 标签字符串

Xamarin xaml Label String

我在 xaml 中有下一个代码,但我有一个错误,我不知道原因

<?xml version="1.0" encoding="utf-8"?>
  <Resources>
  <String name="app_name"> Cloud Client</String>
  <String name="title_section1">Section 1</String>
  <String name="title_section2">Section 2</String>
  <String name="title_section3">Section 3</String>
  <String name="activity_directory_contents_title">Contenido del directorio</String>
  <String name="activity_main_dialog_logout_title"> Titulo </String>

   </Resources>

在MainActivity.cs

设置标题(Resource.String.activity_main_dialog_logout_title)

错误如下:

严重性代码描述项目文件行 错误 CS0117 'Resource.String' 不包含 'activity_main_dialog_logout_title' Cloud_Client_Android C:\Users\Developer\Documents\Visual Studio 2015\Projects\Cloud_Client_Cross-Platform\Cloud_Client_Android\MainActivity.cs 58

的定义

确保文件 (strings.xml) 的构建操作设置为 "Android Resource"

而且格式看起来不对,应该是这样的(可能很重要):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string
        name="string_name"
        >text_string</string>
</resources>

使用 Xamarin.Android 时,您创建的不是 Xaml 文件,而是 android 资源 xml 文件。请参阅 android 站点寻求帮助:http://developer.android.com/guide/topics/resources/string-resource.html

确保 Strings.xml 文件位于 Resources/values(注意大写并将 Strings.xml 设置为 Android 资源),正如 matt 所说,这是正确的 xml 格式

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="btn">OK</string>
</resources>