我在 ILSpy 中打开了 mscorlib,并在资源文件夹中看到:
Name, Value
[Format_InvalidString, Input string was not in a correct format.]
有没有办法本地化这个字符串?
(上下文:只要输入了错误的数字,silverlight 应用程序就会抛出此消息,并且仅更改此消息比编写转换器并将其应用于数百个地方要容易得多)。
我在 ILSpy 中打开了 mscorlib,并在资源文件夹中看到:
Name, Value
[Format_InvalidString, Input string was not in a correct format.]
有没有办法本地化这个字符串?
(上下文:只要输入了错误的数字,silverlight 应用程序就会抛出此消息,并且仅更改此消息比编写转换器并将其应用于数百个地方要容易得多)。
Silverlight 使用附属程序集进行本地化。您可以在 Silverlight 安装位置看到这些内容。在我的机器上,我在 C:\Program Files (x86)\Microsoft Silverlight\5.1.20125.0 中安装了 Silverlight 5,如有必要,请在您的机器上调整版本号。
请注意有 2 个字母名称的许多子目录,例如,“ar”是阿拉伯语的子目录。查看该目录,注意那里的 mscorlib.resources.dll 文件。那是包含本地化字符串的附属程序集,包括异常消息字符串。该特定目录中的阿拉伯语字符串。
并将自动显示在用户选择阿拉伯语作为首选语言的机器上。你不必帮忙。
唯一可行的解决方案是:
public partial class MyEntity
{
public string MyField_string
{
get
{
return MyField.ToString();
}
set
{
decimal res = 0;
var b = Decimal.TryParse(value, out res);
if (!b)
throw new ArgumentException("Localized message");
else
this.MyField = Math.Round(res, 2);
}
}
partial void OnMyFieldChanged()
{
RaisePropertyChanged("MyField_string");
}
}
然后绑定到MyField_string
而不是MyField
.