Click here to Skip to main content
13,146,315 members (46,181 online)
Rate this:
Please Sign up or sign in to vote.
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?

Posted 5-Feb-13 4:44am
Updated 5-Feb-13 7:15am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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()
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;"
Pete O'Hanlon 5-Feb-13 13:00pm
As we can't see your code, we can only guess here. Why don't you actually post some of your code? Give us the namespace and class declarations, and give us the button code - we might have a better idea then.
Hslldm 5-Feb-13 13:16pm
I added the code.
Pete O'Hanlon 5-Feb-13 13:20pm
I've updated my answer.
Hslldm 5-Feb-13 13:43pm
I accept the code but doesn't accept the namespace...(says" identifier expected,namespace is a keyword)...How do i identify it?
Hslldm 5-Feb-13 13:48pm
When I tried
using DXWPFApplication3;
says "could not be found".....
Pete O'Hanlon 5-Feb-13 14:07pm
Is MainWindow_2 in a namespace called DXWPFApplication3? Drop this line and try compiling it up.
Hslldm 5-Feb-13 14:16pm
Yes it is in DXWPFApplication3. I dropped. Still not working.
Pete O'Hanlon 5-Feb-13 14:19pm
Try this then: DXWPFApplication3.MainWindow_2 win2 = new DXWPFApplication3.MainWindow_2().Show();
Hslldm 5-Feb-13 14:46pm
says..."Could not be found" .In the project folder. Those two
in different folders. Can it be because of that?
Pete O'Hanlon 5-Feb-13 14:50pm
Remember that bit where I asked you if they were in the same assembly? That's what I was on about. Add the other assembly in as a reference to the main application.
Hslldm 5-Feb-13 14:56pm
How can i add it?
Pete O'Hanlon 5-Feb-13 15:00pm
Right click on the project in the Solution Explorer, select Add Reference and choose Assemblies - then pick the relevant project. May I also suggest that you buy a book on programming .NET? Seriously, this is basic stuff.
Hslldm 5-Feb-13 15:15pm
It worked!, Thanks. Sorry, i started to learn c# this week and i couldn't find a good source.
Pete O'Hanlon 5-Feb-13 15:17pm
I'm glad it worked, but if you're only starting to learn C#, I would start with something simpler than WPF.
Hslldm 5-Feb-13 15:23pm
Is it too hard?, I have an homework. A form can perform matrix multipication. Will it be too hard?
Pete O'Hanlon 5-Feb-13 15:25pm
For a newcomer? Yes. Put it this way, I've been a professional programmer for the last 25+ years, and I found WPF to be hard when I got into it 5 years ago.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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).
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100