简体   繁体   English

Xamarin.Forms 资源文件未找到

[英]Xamarin.Forms Resource file is not found

I did everything exactly as in this simple guide of how to access strings from another file anywhere in the Xamarin.forms project (in xaml and c#).我所做的一切都与如何从 Xamarin.forms 项目(在 xaml 和 c# 中)中的任何位置的另一个文件中访问字符串的简单指南完全相同。

( https://docs.microsoft.com/de-de/xamarin/xamarin-forms/app-fundamentals/localization/text?pivots=windows ) https://docs.microsoft.com/de-de/xamarin/xamarin-forms/app-fundamentals/localization/text?pivots=windows

However, it will simply not found my resouces, even If I set the build options to embedded resource.但是,即使我将构建选项设置为嵌入式资源,它也不会找到我的资源。

THIS DOESNT WORK:这不起作用:

            <Label
                Grid.Row="1"
                Grid.Column="1"
                FontFamily="arial"
                FontSize="12"
                TextColor="#272727"
                Text="{x:Static local:AppResources.BgColor}" 
                HorizontalOptions="Start" 
                VerticalOptions="Start"/>

Screenshot of resx file and browser resx文件和浏览器的截图

It should work accordning to the manual but im getting: "Type AppResources not found in xmlns dr-namespace:app4.Renderer.它应该根据手册工作,但我得到:“在 xmlns dr-namespace:app4.Renderer 中找不到类型 AppResources。

Please help me out here.请帮帮我。 Otherwise I have so many hardcoded strings in code and xaml files...否则我在代码和 xaml 文件中有这么多硬编码字符串......

Thank you!谢谢!

In the XAML file, add:在 XAML 文件中,添加:

xmlns:resources="clr-namespace:MyApp.Resx"

MyApp = namespace; MyApp = 命名空间; Resx = folder where the resource file is Resx = 资源文件所在的文件夹

The errors shows it can not find the class AppResources under the path app4.Renderer .错误显示它在 app4.Renderer 路径下找不到app4.Renderer AppResources

You have to ensure the path (namespace + folder + classname) is set correctly.您必须确保正确设置路径(命名空间 + 文件夹 + 类名)。

Change the local in scheme as将方案中的local更改为

 xmlns:local ="clr-namespace:App4.Resx"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM