Click here to Skip to main content
15,891,513 members

Solved! opening wpf form from winforms

bassplayer142 asked:

Open original thread
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!
Tags: C# (C# 4.0), WPF, Windows Forms, Integration

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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