简体   繁体   中英

WPF starting a new Winform Cefsharp

I've been working in WPF and trying to start a Winform from that area. The only solution is to open it as a ShowDialog() . Is this a bug or can we expect any problems in the future? my other program is located in the same solution, but not the same namespace.

WindowsFormsApplication1.Form1 program2 = new WindowsFormsApplication1.Form1();
program2.ShowDialog();

I've just tested this, and it works for me:

public partial class MainWindow : Window
{
    private Form winForm;
    public MainWindow()
    {
        InitializeComponent();
    }

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        winForm = new WinForm1();
        winForm.Show();
    }
}

在此处输入图片说明

I believe your problem is most likely due to your program2 going out of scope immediately after you try to call Show on it, which is closing it faster than you can see it. The reason ShowDialog works, is because it is a blocking call, keeps the window in scope and open until after it is closed.

Try declaring program2 as a field within the WPF Window class, instead of as a local variable. That will keep it in scope.

I found the problem... the reason program2.Show() was not working was becouse of Cefsharp during the launch of the second program via javascript the loading progress bar(Javascript) was not done loading. you can identify these problems with Cefsharp by tagging them in to

 if (browser.CanExecuteJavascriptInMainFrame)
                    {
                        WindowsFormsApplication1.Form1 program2 = new WindowsFormsApplication1.Form1();
                        program2.Show();
                    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM