我想为我的 Xamarin 应用程序的所有字符串使用一个资源文件 - 因为我想为我的所有 3 个平台(iOS、Android、UWP)使用相同的字符串,所以我在 Xamarin-Forms 项目中创建了一个新的 resx 文件。但 Visual Studio 未按预期处理该文件...未构建资源的匹配 .cs 文件。但这有必要吗?
我尝试了几种解决方案:
var resourceLoader = new ResourceLoader();
label1.Text = resourceLoader.GetString("String1");
以及
ResourceManager rm =
new ResourceManager("MyApp.Resources1", typeof(MainPage).GetTypeInfo().Assembly);
label1.Text = rm.GetString("String1");
但是在运行时(UWP)我收到错误:
Could not find any resources appropriate for the specified culture or the neutral culture.
这应该只是第一步 - 稍后我希望将 XAML 中的资源中的字符串直接绑定(bind)到控件。
但我认为,我的方式完全错误......并且没有独立于平台的方式来使用字符串资源......?
最佳答案
关于xamarin - 在 Xamarin 中使用字符串资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47436778/