我所做的一切与本简单指南完全相同,有关如何从Xamarin.forms项目(在xaml和c#中)的任何位置访问另一个文件中的字符串。
但是,即使我将构建选项设置为嵌入式资源,也根本找不到我的资源。
不起作用:
<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
它应该按照手册工作,但提示:“键入xmlns dr-namespace:app4.Renderer中找不到的AppResources类型。
请在这里帮助我。否则我在代码和xaml文件中会有很多硬编码的字符串...
谢谢!
答案 0 :(得分:0)
在XAML文件中,添加:
xmlns:resources="clr-namespace:MyApp.Resx"
MyApp =名称空间; Resx =资源文件所在的文件夹
答案 1 :(得分:-1)
错误表明它在路径AppResources
下找不到类app4.Renderer
。
您必须确保正确设置了路径(名称空间+文件夹+类名)。
将方案中的local
更改为
xmlns:local ="clr-namespace:App4.Resx"