Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Winforms应用程序托管在WPF应用程序上_C#_Wpf_Winforms - Fatal编程技术网

C# Winforms应用程序托管在WPF应用程序上

C# Winforms应用程序托管在WPF应用程序上,c#,wpf,winforms,C#,Wpf,Winforms,我需要在WPF应用程序上托管WinForms应用程序。我按照步骤操作,但我有一个错误: System.Reflection.TargetInvocationException未处理 信息:这是一个超越发票目的地的产品 怎么了?我正在使用VS2012和.NET4.5。WinForms应用程序只是一个带有按钮的表单。事件单击显示带有消息的消息框,Hello World仅此而已。我以前使用过WindowsFormsIntegration.dll,它工作正常。这应该可以帮助你开始。首先添加对Window

我需要在WPF应用程序上托管WinForms应用程序。我按照步骤操作,但我有一个错误:

System.Reflection.TargetInvocationException未处理 信息:这是一个超越发票目的地的产品


怎么了?我正在使用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");
    }
}