资源本地化 xaml

8 浏览
0 Comments

资源本地化 xaml

我试图访问资源文件中的字符串,但在TextBlock的文本中出现了错误。

"The name UIResources" does not exist in the

"clr-namespace:ProjectName.Resources"."

文件存在且所有属性都是公开的。我做错了什么吗?

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:local="clr-namespace:MyApp.Project1"

xmlns:p="clr-namespace:MyApp.Project1.Resources"

mc:Ignorable="d"

Title="TestWindow" Height="300" Width="300">

0
0 Comments

问题:Resources localization xaml

原因:需要在XAML文件中添加资源定位的代码

解决方法:

1. 在XAML文件的Window标签内添加以下代码:


    

其中,`local:MyKey`是资源的类型,`x:Key="key"`是资源的键值对。

2. 确保你的资源文件的扩展名是.resx。

3. 如果是针对文本的资源定位,可以在Text属性中添加`ValidatesOnDataErrors=True`,即:

Text="{ValidatesOnDataErrors=True}"

0