===========================更新の開始===================== ================
コード:
using System.Windows; // Window, WindowStartupLocation
using System.Windows.Interop; // WindowInteropHelper
using System.Runtime.InteropServices; // DllImport
...
// Instantiate the owned WPF window
CenteredWindow cw = new CenteredWindow();
// Get the handle to the non-WPF owner window
IntPtr hWnd = ...
CenteredWindow cw = new CenteredWindow();
EnableWindow(hWnd, false); // disable parent window
try
{
// Set the owned WPF window’s owner with the non-WPF owner window
WindowInteropHelper helper = new WindowInteropHelper(cw);
helper.Owner = hWnd;
cw.ShowDialog();
}
finally
{
EnableWindow(hWnd, true); // enable parent window
}
...
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool EnableWindow(IntPtr hwnd, bool enable);
@kamal- nayanのコメントにあるMSConnectLinkの助けを借りて、上記のようにコードを変更しました。これは私にとってはうまく機能します。
重要なのは、親ウィンドウを無効にすることです。モーダルダイアログを閉じたら、親ウィンドウを有効にします。
===========================更新の終了===================== ================
using System.Windows; // Window, WindowStartupLocation
using System.Windows.Interop; // WindowInteropHelper
...
// Instantiate the owned WPF window
CenteredWindow cw = new CenteredWindow();
// Get the handle to the non-WPF owner window
IntPtr ownerWindowHandle = ...; // Get hWnd for non-WPF window
// Set the owned WPF window’s owner with the non-WPF owner window
WindowInteropHelper helper = new WindowInteropHelper(cw);
helper.Owner = ownerWindowHandle;
cw.ShowDialog();
これは私が見つけた唯一の解決策です。これは実際のモーダルではありません。つまり、親をアクティブ化することはできますが、子ウィンドウが親の上にあることは良いことです。
http://blogs.msdn.com/b/wpfsdk/archive/2007/04/03/centering-wpf-windows-with-wpf-and-non-wpf-owner-windows.aspx