【发布时间】:2015-03-31 11:54:14
【问题描述】:
我在 Xaml 中有一个 TextBlock 来显示标题。我曾经设置一个x:Uid="MyTitle",在资源文件中描述。但是现在,我的头衔可以改变了。我尝试绑定我的 .cs 中的标题变量(我们无法绑定 x:Uid)。
所以!我尝试直接在 C# 上更改我的标题并且...我失败了。 这是我的想法:
我的树
Root
Source
-code.xaml
-code.xaml.cs
Resources
En
-resources.resw
"Mytitle_1.Text", "This is my first title"
"Mytitle_2.Text", "This is the other one"
code.xaml
<TextBlock TextWrapping="Wrap" x:Name="Exemples" FontSize="20" Margin="20, 0, 20, 0" LineHeight="25" MaxLines="2" FontFamily="Segoe UI Light" Height="65"/>
code.xaml.cs
private string GetResources(string key)
{
ResourceLoader rl = ResourceLoader.GetForCurrentView("../Resources");
string resources = rl.GetString(key);
return resources;
}
private void ChangeTitle()
{
if (something)
Exemples.Text = GetResources("Mytitle_1");
else
Exemples.Text = GetResources("Mytitle_2");
}
【问题讨论】:
标签: c# wpf xaml windows-store-apps windows-8.1