飞力UI更新,在WPF改变现有的文化后, [英] Force UI update on the fly, after changing current culture in WPF
问题描述
我需要支持通过应用程序菜单UI语言的变化。 该文本使用资源文件(类似于接近1 这里)局部
I need to support UI language change through the application menu. The texts are localized using resource files (similar to approach 1 here)
如果我设置了 Thread.CurrentThread.CurrentUICulture
的构造函数调用的InitializeComponent()
之前,用户界面是改变了,因为它应该。
if I set the Thread.CurrentThread.CurrentUICulture
before the ctor calls to InitializeComponent()
, the UI is changed as it should.
但是,如果的CurrentUICulture
是应用程序的正常运行过程中改变的控件不更新(即文本保持不变,无论当前的文化)
However, if the CurrentUICulture
is changed during the normal run of the application, the controls are not updated (i.e. the text remains the same, regardless of the current culture).
有没有办法强制控制,根据刷新的的CurrentUICulture
?
Is there a way to force the controls to refresh according the the CurrentUICulture
?
推荐答案
您可以使用的的ResourceDictionary
办法随着 DynamicResourceMarkupExtension
。使用这种方法,你可以换出资源字典重新presenting用户选择的语言和 DynamicResourceMarkupExtension
将确保新的价值体现在用户界面。
You could use the ResourceDictionary
approach along with the DynamicResourceMarkupExtension
. Using this approach you can swap out the resource dictionary representing the language the user has selected and the DynamicResourceMarkupExtension
will ensure the new value is reflected in the UI.
另外,如果你愿意冒险进入自定义解决方案的领域,有 LocalizeMarkupExtension
这是在的this WPF教程。
Also, if you're willing to venture into the realm of a custom solution, there is the LocalizeMarkupExtension
which is provided in this WPF tutorial.
这篇关于飞力UI更新,在WPF改变现有的文化后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!