更改文化时 wpf 更新验证错误

发布于 2024-10-11 17:42:18 字数 185 浏览 10 评论 0原文

我有一个支持多语言的应用程序。
当应用程序语言更改时,我可以刷新标签文本并访问每个标签并更改内容。
但是,我无法使用相关语言更改验证错误 (IDataErrorInfo) 文本。
有没有办法更新/刷新错误文本?

不:我尝试获取绑定表达式并强制 UpdateTarget/UpdateSource 方法,但它不起作用。

I have an application that supports multilanguage.
When application language is changed, I can refresh the labels text with access each of the label and change content.
However, I can't change the validation errors (IDataErrorInfo) text with the related language.
Is there a way to update/refresh the errors text?

Not: I try to get binding expression and force UpdateTarget/UpdateSource method, it did not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-10-18 17:42:18

我们有一个包装 IDataErrorInfo 的包装类。使用此类,可以执行 SetFieldError(string fieldName, string error) 或 SetBusinessRuleError(string error)。

这样,您就可以将错误设置为多语言:

SetFieldError("myField", Resources.MyErrorDescription);

当您将字符串移动到资源文件时,您只需设置当前区域性,并确保该区域性资源文件的所有翻译均可用。

然后,对于字段(在本例中为“myField”)的 INotifyPropertyChanged,以便 WPF 引擎知道应该更新该属性。

We have a wrapper class that wraps IDataErrorInfo. With this class, it is possible to SetFieldError(string fieldName, string error) or SetBusinessRuleError(string error).

This way, you can make your errors multilanguage:

SetFieldError("myField", Resources.MyErrorDescription);

When you move the string to a resource file, you only have to set the current culture, and make sure all translations of the resource files of that culture are available.

Then, for the INotifyPropertyChanged for the field (in this case "myField") so the WPF engine knows that the property should be updated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文