更改文化时 wpf 更新验证错误
我有一个支持多语言的应用程序。
当应用程序语言更改时,我可以刷新标签文本并访问每个标签并更改内容。
但是,我无法使用相关语言更改验证错误 (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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们有一个包装 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.