从 XAML 中的 *.resx 文件中获取值 [英] Get values from *.resx files in XAML

查看:41
本文介绍了从 XAML 中的 *.resx 文件中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将资源文件中的某些值直接添加到 XAML 标记中?或者为了本地化,我们总是必须在 *.cs 文件中做这样的事情:

Is it possible to add some value from resource file right into the XAML markup? Or for localization we always have to make something like this in *.cs file:

txtMessage.Text = Messages.WarningUserMessage;

其中 Messages 是资源,txtMessage 是 TextBlock.

Where Messages is resource, and txtMessage is TextBlock.

推荐答案

确保在 resx 编辑器中将 Code Generation 设置为 Public,然后您可以简单地使用:

Make sure that Code Generation is set to Public in the resx editor, then you can simply use:

<TextBlock Text="{x:Static Messages.WarningUserMessage}" />

这篇关于从 XAML 中的 *.resx 文件中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆