Click here to Skip to main content
15,669,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A WPF Form, I use C#;

I have a window named "MainWindow_1" and another named"MainWindow_2",

in MainWindow_1 I have a button to open "MainWindow_2". My codes are:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Shapes;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Ribbon;
using DevExpress.Xpf.Bars;
using namespace.DXWPFApplication3;

namespace DXWPFApplication16 
    public partial class MainWindow_1 : DXRibbonWindow
        public MainWindow_1()


        private void Button_Click_1(object sender, RoutedEventArgs e)


        private void Button_Click_2(object sender, RoutedEventArgs e)

           MainWindow_2 win2 = new MainWindow_2.Show();
//I want this button opens another WPF form (which namespace DXWPFApplication3)//




But VS2012, underlines "MainWindow_2" word.It says "Type or namespace couldn't be found"

How can i solve it?

Updated 5-Feb-13 7:15am

You need to add a reference to the namespace that MainWindow_2 is in to the code for MainWindow_1. If MainWindow_2 is in a separate assembly, you may need to reference that assembly as well.

[OP has updated question with code]
MainWindow_2 win2 = new MainWindow_2.Show()

Should be

MainWindow_2 win2 = new MainWindow_2().Show()
Share this answer
Hslldm 5-Feb-13 11:00am    
I am new at C#, could you tell me have to do that

Thanks.(It's in the same assembly)
Pete O'Hanlon 5-Feb-13 11:30am    
At the top of the code behind (I'm assuming you aren't doing this via MVVM), type in "using Namespace_That_MainWindow_2_Resides_In;" (without the quotes). Obviously you'd replace that namespace text with the actual namespace that MainWindow_2 resides in.
Hslldm 5-Feb-13 12:06pm    
I wrote this:
using Namespace_that_MainWindow_2_Resides_In;

But it didn't accept it. I tried this then;
using namespace.DXWPFApplication3;

Now VS accepts the MainWindow_2(Remove the red underlines), but now doesn't
accept "namespace" word in the using place. Says "identifier expected, namespace is a keyword".

What should i do?
Thank you very much.
Pete O'Hanlon 5-Feb-13 12:47pm    
In the code behind, you don't need to use namespace in the using statement. So, in this case, you'd use: using DXWPFApplication3;
Hslldm 5-Feb-13 12:53pm    
Nope, it didnt work. underlined "DXWPFApplication3;"
Just press Ctrl + . on MainWindow_2 in the line MainWindow_2 win2 = new MainWindow_2();
It will resolve your name space (if the dll is already part of the project).
Share this answer
Hslldm 5-Feb-13 11:13am    
It didn't work

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