WPF,本地化:重新评估控制值
我正在对 WPF 中的本地化方法进行一些小研究。我听说过标记扩展的想法:
我非常喜欢这个解决方案:它非常简单实施并且似乎非常灵活。不过,我有一个担忧。假设用户在运行时更改了区域设置。如何确保重新评估本地化属性以匹配新语言?
I'm doing a small research on localisation methods in WPF. I heard about the idea with markup extension:
<Label Content="{local:Translate {-- label ID here --}}" />
I like this solution very much: it's extremely easy to implement and seems to be nicely flexible. I've got one concern, however. Let's suppose, that user changes the locale in the runtime. How to ensure, that localized properties will be reevaluated to match new language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要调用 DependencyObject.InvalidateProperty。请记住,如果您绑定到实现 INotifyPropertyChanged 的对象,它们将通过底层数据更改的方式重新评估。
可以在给定的
DependencyProperty
(例如Label.Content
)上调用DependencyObject.InvalidateProperty
。对于需要重新评估的不同属性,必须执行此操作。 MSDN 上有一篇关于 WPF 中本地化的深入文章,提供了不同的替代方案也应该进行调查。
You would need to call DependencyObject.InvalidateProperty. Keep in mind that if you were binding to an object implementing
INotifyPropertyChanged
they would reevaluate by way of the underlying data changing.DependencyObject.InvalidateProperty
can be called on a givenDependencyProperty
such asLabel.Content
.This would have to be done for the varying properties that need re-evaluation. There is an in depth article on MSDN around localization within WPF for varying alternatives as well that should be investigated.