设置资源字符串为XAML [英] Set resource string to XAML

查看:227
本文介绍了设置资源字符串为XAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何设置从资源结果
字符串< TextBlock的X:UID =文本1/>
,其中 Text1.Text 是你好



但我想要做这样的

 < TextBlock的文本= {东西在这里得到GreetingText} /> 



其中, GreetingText 是你好



所以,我可能会从代码也相同的字符串为

  VAR装载机=新Windows.ApplicationModel.Resources.ResourceLoader(); 
无功串= loader.GetString(GreetingText);


解决方案

Nikhil的答案是正确的轨道上,但是是正确的对于其他平台



有关Windows 8中,你需要做在你的资源目录以下内容:

 < X:字符串x:键=MyString的>这是一个资源< / X:字符串> 

在您的XAML:

 < TextBlock的文本={StaticResource的MyString中}/> 

在代码:

 字符串的myString =(字符串)(App.Current.Resources [MyString的]); 


I know how to set string from resource
<TextBlock x:Uid="Text1"/> where Text1.Text is "Hello"

But I want to do like this

<TextBlock Text = {something here to get GreetingText}/>

where GreetingText is "Hello"

So that I may get the same string from code also as

var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
var string = loader.GetString("GreetingText");

解决方案

Nikhil's answer is on the right track, but is right for other platforms.

For windows 8, you need to do the following in your resource directory:

<x:String x:Key="MyString">This is a resource</x:String>

In your xaml:

<TextBlock Text="{StaticResource MyString}"/>

In code:

string myString = (string)(App.Current.Resources["MyString"]);

这篇关于设置资源字符串为XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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