0

I have 2 projects, both in C# wpf. I want to combine them into an unique one.

What I want exactly, is to call form-2 in project 2 from my project 1 form-x.

I have tried with this article from MSDN but it's not what I want.

http://msdn.microsoft.com/en-us/library/ms747086.aspx

http://msdn.microsoft.com/en-us/library/ms747086.aspx
<Page x:Class="WPFApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:SDKSample;assembly=SDKSampleLibrary">

...

Any ideas please.

David Pilkington
  • 13,528
  • 3
  • 41
  • 73
user2933082
  • 263
  • 3
  • 10

2 Answers2

1

You should be able to add Project 2 as a reference to Project 1.

Then you should be able to use the namespace.

EDIT:

Try this (I am assuming you are using VS)

How to: Add or Remove References By Using the Add Reference Dialog Box

David Pilkington
  • 13,528
  • 3
  • 41
  • 73
  • my secondary project is called MonitoringSystemOfficeArea i have put xmlns:custom="clr-namespace:MonitoringSystemOfficeArea;assembly=MonitoringSystemOfficeArea"> but it does not work, im i missing something ? – user2933082 Oct 31 '13 at 12:41
  • But have you actually included the DLL in your project? If you are using Visual Studio, right click on the references folder in the project and select Add reference. The select the secondary project from the list. – David Pilkington Oct 31 '13 at 12:51
  • how could i include it as dll ? should i use classlibrary ? – user2933082 Oct 31 '13 at 12:56
  • What IDE are you using? – David Pilkington Oct 31 '13 at 12:57
  • If you have your other "project" as a DLL or EXE, you need to add it as a reference. An easy way to do this would be to add the other project to your solution (and then just add a reference to the project). Note: this requires any object you want to use to be `public`. – crashmstr Oct 31 '13 at 13:08
  • @ crashmstr its working now i have add .exe in my 2 solution as referance and by using "using MonitoringSystemOfficeArea;" the second question is how can i call the frmMain from my first project ? thank you – user2933082 Nov 04 '13 at 09:15
  • Perhaps that would be better placed in it own question as this one has been resolved. – David Pilkington Nov 04 '13 at 09:32
  • ok i have found how to do this, by using the name space alike the name of the ".exe" i can call the form by using MonitoringSystemOfficeArea.MainWindow wind = new MonitoringSystemOfficeArea.MainWindow(); wind.Show(); note that .MainWindow is the name of the first form in my 2 project – user2933082 Nov 04 '13 at 09:36
-2

If you have two WPF forms in two different projects then the only way to open the form in another process is calling its executable. For example:

You have two WPF Projects (Form1.exe and Form2.exe outputs) that builds two separate exe. When you would like to open Form1 in Form2 you can call its process:

System.Diagnostics.Process.Start("Path of Form2.exe");

Another option is to keep 2 executables running and send messages to each other to open a form. You need Inter Process Communication in this case.

The solution that seems will be working for you:

If it is possible convert your projects into class library (DLL file) create one application and reference these two DLL files. Then you can easily open any form that you want easily.

Community
  • 1
  • 1
Demir
  • 1,787
  • 1
  • 29
  • 42
  • You can add a reference to an .net exe and use (public) objects from it. – crashmstr Oct 31 '13 at 12:35
  • @Demir how can i convert my entire project to .dll ? – user2933082 Oct 31 '13 at 12:36
  • @user2933082 To convert project into class library open project properties in VS go to Application tab and select 'Output Type' as Class Library. Then delete App.xaml file (your application definition) from the project. – Demir Oct 31 '13 at 13:55