Reputation: 136
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();
Upvotes: 0
Views: 465
Reputation: 136
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();
}
Upvotes: 0
Reputation: 17001
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.
Upvotes: 1