解决了!从WinForms打开WPF表单 [英] Solved! opening wpf form from winforms

查看:111
本文介绍了解决了!从WinForms打开WPF表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是新来的,并经常使用此网站寻求帮助.到目前为止,它是一种很棒的资源,我很高兴地说它已经起到了很大的作用.我主要是一名工程师/嵌入式专家,但是我需要从事一些GUI和通信协议的工作.我只使用c#或任何OOP语言大约一个月,所以请多多包涵.

我已经将我的基本交流和背景代码编码在winforms中,我需要开始使用wpf制作动画和GUI.不幸的是,我的Winforms中的计时器图形系统在较慢的计算机上落后,并且是不可接受的.

我发现从winforms打开wpf窗口的主题很少.我已经附加了我的项目,该项目在引用命名空间时出错.我在解决方案中的wpf和winforms项目中都使用了相同的引用.代码如下.


winforms代码...

Hi everyone, I''m new here and have used this site very frequently for help. It is a great resource so far, and I''m happy to say it has helped a lot. I''m primarily an engineer/embedded guy, but I''m needed to work on some GUI''s and communication protocols. I''ve only been doing c# or any OOP language for about a month so bear with me.

I''ve got my base communication and background coded in winforms and I need to start using wpf for animations and the GUI. Unfortunately, my timer graphical system in winforms lags on slower computers and is unacceptable.

I''ve found very few topics on opening a wpf window from winforms. I''ve attached my project which has an error in referencing the namespace. I''ve used the same references in both the wpf and winforms projects that are in my solution. The code is as follows.


winforms code...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Windows.Forms.Integration;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


        }

        private void button1_Click(object sender, EventArgs e)
        {
            var wpfWindow = new WpfApplication1.MainWindow();
            //var wpfWindow = new WpfApplication1.MainWindow();
            wpfWindow.Show();
        }
    }
}



wpf代码...



The wpf code...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Windows.Forms.Integration;


namespace WpfApplication1
{

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}





错误在这里...

错误1找不到类型或名称空间名称``WpfApplication1''(您是否缺少using指令或程序集引用?)C:\ Users \ alna072683 \ Desktop \ wpftowin \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ Form1.cs 34 33 WindowsFormsApplication1





如果有人能让我知道我在做错什么,那太好了!





The error is here...

Error 1 The type or namespace name ''WpfApplication1'' could not be found (are you missing a using directive or an assembly reference?) C:\Users\alna072683\Desktop\wpftowin\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 34 33 WindowsFormsApplication1





If anyone could let me know what I''m doing wrong that would be great!

推荐答案

假设您使用的是Microsoft Visual C#,请转至:project->添加参考->浏览并添加wpf文件.这应该可以解决您的错误
assuming you are using microsoft visual c# go to: project -> add reference -> browse and add the wpf file. this should solve your error


这篇关于解决了!从WinForms打开WPF表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆