简体   繁体   English

UWP-如何从控件获取字符串资源?

[英]UWP - How can I get strings resources from controls?

I would like to add some languages in my app. 我想在我的应用程序中添加一些语言。

For example I would show with a xaml page: 例如,我将显示一个xaml页面:

<TextBlock x:Name="helloText" Text="Hello"/>

I saw that I can write on xaml.cs 我看到我可以在xaml.cs上写

helloText.Text=ResourceNamespace.ResxFileName.ResourceManager.GetString("Hello");

but isn't there a more direct solution? 但是没有更直接的解决方案吗?

Isn't there a way to add reference directly to Text attribute into the xaml page? 是否没有办法将对Text属性的引用直接添加到xaml页面中?

On MSDN I didn't find the answer, thanks. 在MSDN上,我找不到答案,谢谢。

you need to set the x:Uid of the text block to something, lets say x:Uid=myTextBlock . 您需要将文本块的x:Uid设置为某种值,例如x:Uid=myTextBlock

in your Resources.resw file, add a entry myTextBlock.Text with value of the text you want to display. 在您的Resources.resw文件中,添加条目myTextBlock.Text ,其值为您要显示的文本的值。

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

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