Click here to Skip to main content
15,891,757 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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...

C#
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();
        }
    }
}


The wpf code...

C#
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();
        }
    }
}




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!
Posted
Updated 25-Sep-12 5:27am
v2

1 solution

assuming you are using microsoft visual c# go to: project -> add reference -> browse and add the wpf file. this should solve your error
 
Share this answer
 
Comments
bassplayer142 25-Sep-12 11:27am    
Thank you sir! It worked right away.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900