2
這個問題的反面已被回答了很多次。如何從WPF窗口顯示Winforms對話框?
public static void SetOwner(object activeWindow, object dialog)
{
if (IsWindow(dialog) && IsWindow(activeWindow))
{
(dialog as Window).Owner = (activeWindow as Window);
}
else if (IsForm(dialog) && IsForm(activeWindow))
{
(dialog as Form).Owner = (activeWindow as Form);
}
else if (IsWindow(dialog) && IsForm(activeWindow))
{
var wih = new WindowInteropHelper(dialog as Window);
wih.Owner = (activeWindow as Form).Handle;
}
else if (IsForm(dialog) && IsWindow(activeWindow))
{
var dialogForm = dialog as Form;
var ownerWindow = activeWindow as Window;
// What goes here?
}
}
此問題:http://stackoverflow.com/questions/1095763/how-to-set-a-wpf-window-as-the-owner-of-a-winforms-form –
你不必指定一個所有者,Form.ShowDialog()會找到一個。 –