使用 WinForms 启动 WPF 应用程序 window
Start WPF application with WinForms window
我有 WPF
申请和一些 WPF
windows。但是我的主要 window 是 WinForms
,我需要用它来启动程序。但是我该怎么做呢?这是我的 App.xaml
文件:
<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>
如果我尝试用 StartupUri="UI/Form1.cs"
替换 StartupUri="UI/MainWindow.xaml"
,我会得到 "System.IO.IOException", "Cannot find "ui/form1.cs"
。甚至可以使用 WinForms
window 启动我的应用程序吗?
MSDN 上有一篇很好的文章为您提供了如何在 XAML 中集成 Windows-Forms 元素的示例:https://msdn.microsoft.com/de-de/library/ms742875(v=vs.110).aspx
应该对你的假设有帮助。
首先转到 App.xaml 并删除 StartupUri="UI/MainWindow.xaml"
。
比转到 App.xaml.cs 并覆盖 OnStartup 方法。在那里你可以实例化 运行 你的胜利形式 window.
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var form = new Form1();
form.Show();
}
我有 WPF
申请和一些 WPF
windows。但是我的主要 window 是 WinForms
,我需要用它来启动程序。但是我该怎么做呢?这是我的 App.xaml
文件:
<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>
如果我尝试用 StartupUri="UI/Form1.cs"
替换 StartupUri="UI/MainWindow.xaml"
,我会得到 "System.IO.IOException", "Cannot find "ui/form1.cs"
。甚至可以使用 WinForms
window 启动我的应用程序吗?
MSDN 上有一篇很好的文章为您提供了如何在 XAML 中集成 Windows-Forms 元素的示例:https://msdn.microsoft.com/de-de/library/ms742875(v=vs.110).aspx
应该对你的假设有帮助。
首先转到 App.xaml 并删除 StartupUri="UI/MainWindow.xaml"
。
比转到 App.xaml.cs 并覆盖 OnStartup 方法。在那里你可以实例化 运行 你的胜利形式 window.
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var form = new Form1();
form.Show();
}