JustLogin
JustLogin

Reputation: 1886

Start WPF application with WinForms window

I have WPF application with some WPF windows. But my main window is WinForms and I need to start program with it. But how can I do this? This is my App.xaml file:

<Application x:Class="Player.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="UI/MainWindow.xaml">
    <Application.Resources>
    </Application.Resources>
</Application>

If I try to replace StartupUri="UI/MainWindow.xaml" with StartupUri="UI/Form1.cs", I get "System.IO.IOException", "Cannot find "ui/form1.cs". Is it even possible to start my app with WinForms window?

Upvotes: 0

Views: 2204

Answers (2)

Nikola.Lukovic
Nikola.Lukovic

Reputation: 1325

First go to App.xaml and remove StartupUri="UI/MainWindow.xaml". Than go to App.xaml.cs and override OnStartup method. In there you can instantiate and run your win forms window.

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);
    var form = new Form1();
    form.Show();
}

Upvotes: 1

rbr94
rbr94

Reputation: 2287

There is a good article from MSDN which provides you an example how to integrate an Windows-Forms element in XAML: https://msdn.microsoft.com/de-de/library/ms742875(v=vs.110).aspx

It should be helpful for your suppose.

Upvotes: 0

Related Questions