如何强制在 WPF DLL 中使用特定的 .resx 文件?
我有一个从非托管 DLL 调用的 WPF DLL。 WPF DLL 有一个已翻译的对话框(两组 .resx 文件)。
如果我从 WinForm shell 或另一个 WPF shell 调用 WPF DLL,我可以通过设置当前线程的区域性来强制对话框使用特定语言(.resx 文件)。
但是,当从 C++ DLL 调用 WPF DLL(通过互操作 - COM)时,我无法让 WPF 对话框切换到默认语言以外的任何语言。
我不一定需要读取当前的系统区域性,因为非托管 DLL 的做法有所不同。我想告诉 WPF DLL 当我运行它时使用什么语言。
如何强制它在运行时加载特定语言?
I have a WPF DLL being called from an unmanaged DLL. The WPF DLL has a dialog that has been translated (two sets of .resx files).
If I call the WPF DLL from a WinForm shell, or another WPF shell, I can force the dialog to a particular language (.resx file) by setting the Culture of the current thread.
However, when calling the WPF DLL (through interop - COM) from the C++ DLL, I can't get the WPF dialog to switch to any language other than the default.
I don't necessarily need to read the current system culture, because the unmanaged DLL does it differently. I would like to tell the WPF DLL what language to use when I run it.
How can I force it to load with a particular language at runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以尝试的方法:
在一次调用中设置区域性并创建对话框,如下所示:
通过互操作从 C++ 调用时,NET Framework 必须将本机线程绑定到 NET Framework 线程。我不记得细节了,但我记得有关 NET Framework 线程重用和垃圾收集的机制的一些信息。如果您正在调用设置区域性的托管代码,并第二次调用来创建窗口,则可能的情况是:
这种事件序列是可以想象的,具体取决于托管本机线程绑定代码的实现。因此,我建议您尝试在一次调用中执行这两项操作,看看它是否会改变任何内容。
Something to try:
Set the culture and create the dialog in a single call, like this:
When calling from C++ through interop, NET Framework must bind your native thread to a NET Framework thread. I don't remember the details, but I remember something about a mechanism where NET Framework threads are reused and garbage collected. If you are making a call to managed code that is setting the culture and a second call to create the window, a possible scenario is:
Such a sequence of events is conceivable, depending on the implementation of the mangaged-native thread binding code. Therefore I suggest you try doing both in a single call to see if it changes anything.