如何在资源值字符串中包含资源键

时间:2015-08-17 09:41:28

标签: c# xaml localization windows-8.1

我有用于多品牌的Windows 8应用程序,在我的资源文件中有关键字“AppName”,其中包含品牌名称,我需要将此键包含在需要应用程序名称的值字段中。例如我想在资源文件

中输入这种类型的条目
 1>"AppName" = "xyz"
 2>"WelcomeMessage" = "Welcome to "AppName" app"
 3>"Someotherstring" = "Blah BLah Blah "Appname" blah"

2 个答案:

答案 0 :(得分:0)

在资源中添加一个名为“ApplicationTitle.Text”的字符串资源和“AppName”的值。

然后在XAML中创建一个TextBlock:

<TextBlock x:Uid="ApplicationTitle" Text="" />

在运行时,Text的{​​{1}}将是字符串资源的值。

答案 1 :(得分:0)

你的意思是:

Resource.resx

"AppName" : "Some-brand-name"
"WelcomeMessage" : "Welcome to $AppName$ app"
"Someotherstring" : "Blah blah blah $AppName$ blah"

在代码中:

 var appName = Properties.Resources.AppName;
 var welcomeMessage = Properties.Resources.WelcomeMessage.Replace("$AppName$", appName);
 var someotherstring = Properties.Resources.Someotherstring.Replace("$AppName$", appName);