开发者

How to force a particular .resx file to be used in a 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 she开发者_C百科ll, 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?


Something to try:

Set the culture and create the dialog in a single call, like this:

// Managed code
void SetCultureAndShowWindow(CultureInfo culture, ... more parameters for creating window ...)
{
  Thread.CurrentThread.CurrentCulture = culture;
  Window window = new Window(...
  window.ShowDialog();
}

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:

  1. You call the managed code to set the culture.
  2. A new managed thread is created
  3. Your call returns, and the managed thread is released.
  4. You call the managed code to create and show the window.
  5. A new managed thread is created
  6. The window shows with the wrong culture

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜