C# Winforms应用程序托管在WPF应用程序上
我需要在WPF应用程序上托管WinForms应用程序。我按照步骤操作,但我有一个错误: System.Reflection.TargetInvocationException未处理 信息:这是一个超越发票目的地的产品C# Winforms应用程序托管在WPF应用程序上,c#,wpf,winforms,C#,Wpf,Winforms,我需要在WPF应用程序上托管WinForms应用程序。我按照步骤操作,但我有一个错误: System.Reflection.TargetInvocationException未处理 信息:这是一个超越发票目的地的产品 怎么了?我正在使用VS2012和.NET4.5。WinForms应用程序只是一个带有按钮的表单。事件单击显示带有消息的消息框,Hello World仅此而已。我以前使用过WindowsFormsIntegration.dll,它工作正常。这应该可以帮助你开始。首先添加对Window
怎么了?我正在使用VS2012和.NET4.5。WinForms应用程序只是一个带有
按钮的表单
。事件单击显示带有消息的消息框
,Hello World
仅此而已。我以前使用过WindowsFormsIntegration.dll,它工作正常。这应该可以帮助你开始。首先添加对WindowsFormsIntegration的引用。然后
using System.Windows.Forms.Integration;
发布你的代码和XAML。还有,你想要它做什么?这看起来像一个可怕的黑客。
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var form = new Form1();
form.TopLevel = false;
WindowsFormsHost host = new WindowsFormsHost();
host.Child = form;
host.VerticalAlignment = System.Windows.VerticalAlignment.Top;
host.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
grid.Children.Add(host);
}
<Window x:Class="WpfSandbox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Loaded="Window_Loaded">
<Grid x:Name="grid">
</Grid>
</Window>
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("hello");
}
}