Reputation: 127
I have a WPF application and want to launch a regular Windows Form first by default. It will be an options panel, basically.
edit: for clarification, I'd like the Windows Form to be the only form that opens automatically. I'll then show the WPF form later.
I tried modifying App.xaml:
<Application x:Class="The_Name_Of_My.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Form1.cs">
<Application.Resources>
I get an error: "Cannot locate resource 'form1.cs'." Am I just spinning my wheels here and trying to do something stupid when I should be making the options panel in WPF?
Upvotes: 2
Views: 4360
Reputation: 1
I have same problem for loading Windows_Form_Application as default. But the answer is below... just add a Windows_Form in your project and replace below code to MainWindow.xaml.cs
public MainWindow()
{
InitializeComponent();
//Make WPF form unvisible
this.AllowsTransparency = true;
this.Background = null;
this.WindowStyle = WindowStyle.None;
//Run windows from
Form1 u = new Form1();
u.Show();
//Set close handle to form
u.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
}
private void Form1_FormClosing(object sender, EventArgs e)
{
//close WPF form if windows form being close
this.Close();
}
that's it...
Upvotes: 0
Reputation: 28059
Just instantiate the Windows form in your WPF Form's/Viewmodels constructor and call ShowDialog:
namespace WpfApplication11
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var form1 = new Form1();
form1.ShowDialog();
Close();
}
}
}
Upvotes: 3