从资源中写入wpf中的标签内容 [英] write content of label in wpf from resources

查看:70
本文介绍了从资源中写入wpf中的标签内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

我是wpf应用程序的新手,想要使用标签内容属性来使用来自resources.resx的文本,该文本位于wpf应用程序的内部属性中。

Dear Sir,
I am new in wpf application and want to use the label content property to use for its text from resources.resx which is inside properties in wpf application.

推荐答案

在resx中创建字符串资源项。 Visual Studio中的resx注释具有带有自动生成代码的子节点。打开此文件。您将找到名称相同或接近字符串资源名称的静态类成员。立即使用:

Create string resource item in your resx. The resx note in Visual Studio has a sub-node with auto-generated code. Open this file. You will find a static class member with the name identical or close to the name of your string resource. Use it immediately:
System.Windows.Controls.Label myLabel = //... usually generated in your *.xaml.cs file; or create it by yourself in code

//...

myLabel.Text = Resource.MyResource.MyLabel; // find exact name from the file I mentioned above



另一种方法是使用XAML资源而不是resx。不幸的是,它不会为您提供自动生成的代码文件,但您可以使用Windows,页面或用户控件的XAML中的资源。请参阅:

http:// msdn .microsoft.com / zh-CN / library / ms750613%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/aa348820%28v=vs.110%29.aspx [ ^ ],

http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight .aspx [ ^ ]。



-SA


The alternative is using XAML resources instead of resx. Unfortunately, it won't give you auto-generated code file, but then you would be able to use the resources in your XAML of your windows, pages or user controls. Please see:
http://msdn.microsoft.com/en-us/library/ms750613%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/aa348820%28v=vs.110%29.aspx[^],
http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight.aspx[^].

—SA


这篇关于从资源中写入wpf中的标签内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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