loading a WPF application in a grid!?

Hi,

i wrote a wpf application, that runs in a window.

Now, i am writing another application that consits of 2 grids:
- the Left hand side grid will hold some new code
- I want to load the application i had previously written in the right hand side grid (or something similar)...

1) How can I do this?

2) In .net 2 i used to write DLLs - how can this be done in WPF?

thanks for you help!Smile

-
Visual Studio 2005
C#

[543 byte] By [Guy007] at [2008-1-2]
# 1
you can convert your application to XBap application and then load in into Frame element
TamirKhason at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Hello, if you can turn your first application into an XBap, please use Tamir Khason’s solution. It’s very easy. Just set your Frame’s Source property to the first application’s location, such as E:\XBapApplication.xbap

Your second application don’t have to be an XBap.

If you can’t turn the first application into an XBap, it’ll be quite difficult. Here’s a work around. It only works when you don’t want to modify the window of your first application (such as height, title, etc.) you want to display.

Assembly firstAssembly = Assembly.Load("AnotherApplication");

Window w = (Window)firstAssembly.CreateInstance("AnotherApplication.Window1");

FrameworkElement fe = (FrameworkElement)w.Content;

w.Content = null;

grid1.Children.Add(fe);

w.Close();

This solution uses Reflection. First we must add a reference to the first application. Then we can load its Assembly. Since Window1 of the first application is a Window, we don’t need to get its actual type. Then we can get the Window’s Content. Normally it’s a FrameworkElement. Since every element can have only one parent, before adding it to our Grid, we must disconnect it. We can do this by setting the parent Window’s Content to null. Then we can add the content to our Grid. Finally, since we don’t need the Window any more (we only need its content), we should Close it. We can’t modify the Window’s properties since actually we don’t have the Window. But everything in the Window’s content will show properly. The events will also be fired properly. You can even create another Window if you want. Say, if the Window’s content you display contains a button, your first application’s event handler will be invoked properly. But you can’t directly invoke the handler in the second application unless using reflection, which can be very difficult.

Also for your second question, well, you can create a Custom Control Library application. This is a dll.

Yi-LunLuo-MSFT at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified