My main issue is as I stated in title.
WPF_APP1 --> I created dll of this wpf project after excluding App.xaml
WPF_APP2 --> Normal WPF exe. which needs to run the above WPF_APP1 dll and open the WPF_APP1 MainWindow form using reflection.
Why I am saying for reflection is - WPF_APP2 first get the latest WPF_APP1.dll then open so can not add the reference of dll. have to use the Reflection only.
When I use the above dll in cmd project its okay. it open the CMD window then launch the WPF_APP1 MainWindow as Window form.
But Now I need to open this window form not in cmd, in WPF_APP2.
Please help me out.
CMD project use the below code to open the WPF_APP1 MainWindow.
static void Main(string[] args)
{
Thread t = new Thread(ThreadProc);
t.SetApartmentState(ApartmentState.STA);
t.IsBackground = true;
t.Start();
Console.ReadLine();
}
private static void ThreadProc()
{
string loc = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName
+ "\\AutoUpdateTesting.dll";
Assembly dll = Assembly.LoadFile(loc);
foreach (Type type in dll.GetExportedTypes())
{
if (type.Name.Equals("MainWindow"))
{
dynamic n = null;
n = Activator.CreateInstance(type);
n.InitializeComponent();
System.Windows.Application apprun = new System.Windows.Application();
apprun.Run(n);
break;
}
}
}
I can not use line -
System.Windows.Application apprun = new System.Windows.Application();
In WPF_APP2 because of AppDomain(found this reason on google). Try other alternative but no luck.
Please have a look and share your knowledge. :)
waiting for your comments and reply.
Thanks
Load WPF window from forms application:
That does the trick for forms! Remember that you need to add references to the base WPF assemblies(PresentationCore, WindowBase+++)
WPF loading external window (Read your post wrong, so here you have wpf to wpf as well)
Hope it helps!
Cheers
Stian
Not an answer, but a suggestion:
I would change :
with:
Let linq worry about it, and make your code easier to read and maintain.