Winform dialog with WPF window as Parent

怎甘沉沦 提交于 2021-02-07 11:29:10

问题


I have a WinForm dialog and I want to set its Parent property to a WPF window. How can I do this?


回答1:


Consider passing parameter to ShowDialog method instead of using Parent property.

You can write helper class

class Wpf32Window : IWin32Window
{
  public IntPtr Handle { get; private set; }

  public Wpf32Window(Window wpfWindow)
  {
    Handle = new WindowInteropHelper(wpfWindow).Handle;
  }
}

public static class WindowExtensions
{
  public static IWin32Window GetWin32Window (this Window parent)
  {
    return new Wpf32Window(parent);
  }
}

After that you can just write

winFormsWindow.Show(yourWpfWindow.GetWin32Window());


来源:https://stackoverflow.com/questions/7822164/winform-dialog-with-wpf-window-as-parent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!