Event Aggregration between WPF and Silverlight - wpf

I have one silverlight application hosted in WPF environment.
i have created one static eventaggregrator class.
which is used between multiple modules hosted using prism.
but for the event which need to be publish from a module developed in WPF and subscribe in the module developed in *silverlight*.
is it possible? if yes then can anybody give me some ref article or solutions?

WPF and Silverlight use different execution environments, so code cannot be shared at runtime.
If you are hosting the Silverlight control inside a WebBrowser control in WPF then you will have to insert a Javascript layer inbetween your Silverlight control and the WPF host.
So you will subscribe in the .NET world, and then use the InvokeScript() method on your WebBrowser control to invoke a Javascript script which can communicate with the Silverlight control (see ScriptableMember).

Related

How to open a WPF exe from within a VB6 dll?

This is a question about design approach. I have limited COM experience and a little WCF experience. My constraints are given by the application environment, but I have some design flexibility.
From within a VB6 dll, I need to start, and communicate with, a WPF application. The WPF application is currently an exe, but I could make it a library if that helped. I would like to provide two way communication between the VB6 dll and the WPF application. I have some flexability to adjust the design of the VB6 dll.
I'm developing C# using in VS2010 and .NET 4.
How many components should I use? Can I start the WPF application In-Proc with the VB6 dll? Should there be a third component between them? Can COM+ play a helpful role? Do I have to make the entire WPF application COM-visible? Is there a down-side to doing this?
I'm looking for a design approach that I can prototype. I'm willing to research the details.
I would
Create a Web Service from the WPF application, using WCF. I would abstract out those aspects of the WPF application which should be accessed remotely. This would explicitly not include any of the user interface code.
I would create a simple class library project, and use "Add Service Reference" to add a reference to the WCF service.
I would make the methods of the class library COM-visible
I would call those methods from VB6
This has the benefit of removing any considerations of user interface from the equation.
Out of the options available I like the COM option more than the 'start another process' option for the simplicity that the inter 'application' communication will be via method calls rather than WCF or anything similar.
I am assuming that your VB DLL lives in a window'd process and not a service or web application. You would only need to mark any exposed types as COM visible, that is the classes, their argument and return types.
You may have to wrap your WPF UI inside the windows forms ElementHost [1] but I'm not sure, try it and see.
I'm not sure if you saw this [2] in your search, it sounds do-able but unsupported, ok as long as you don't have too much going on.
[1] http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx
[2] http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7555ba6a-1359-4dfe-aa23-c31a8f121142/
I work on an application primarily written in VB6 but most of the recent code is written in .net with UI components built in WPF and some WinForms. Datasources for this application are WCF, MSSQL server, and a propritary unix based server. All the WCF calls are made from data access components referenced by the .net UI components.
You can host WPF in VB6 windows or other container controls. Start by getting the Interop Forms Toolkit and build shell user controls to host your WPF controls.
To be able to host WPF in these controls you need to build a WinForms usercontrol which contains a ElementHost, which you can set the content to your WPF usercontrol.
WPF Usercontrol inside an Element Host inside a
WinForms usercontrol inside a VB6 usercontrol or
window
The interop toolkit will want to build VB.Net code but you can do it in C#, although I have not tried this. The usercontrols created by the interop toolkit will be exposed as COM components which you can reference VB6 by adding them as components via Project > Components and then you will find them in the toolbox.
In terms of data sources (WCF, databases) etc, you should build all your data access in .net components referenced directly from the UI components, don't try to call back in to VB6 libraries, you will probably just create a mess.
In my application I also have a configuration section which I call from the VB6 application startup which sets up an IoC container for all the .net components.
From a best practice approach I actually would recommend rewriting your VB6 code to .net and putting VB6 out of the picture. If this is not an option then you have a number of options, my explanation is just one of them.

.Net 2.0 custom controls and WPF

out of curiosity i just want to know those custom control which was developed in .Net 2.0 version that can be reused in WPF application. if yes then what would be the process. usually we add custom control to the toolbox and just drag & drop those onto form and easily manipulate and work with them. so can we follow the same step to include those custom control developed with .net v2.0 onto WPF form or not. please discuss. thanks
You can reuse Windows Forms Controls in a WPF application (and the reverse is also true, you can host WPF controls in a Windows Forms application) .
Here is an official documentation link on this subject: Walkthrough: Hosting a Windows Forms Composite Control in WPF

Can i use Activex with silverlight4?

I need to use a ActiveX control in my silverlight application. After some research i found out a few ways in which a silverlight app can use ActiveX control
Use ActiveX control in a webpage along with silverlight plugin and use javascript for interaction between silverlight and activex.
Use a webbrowser control in silverlight 4 and load the webpage containing activex in webbrowser control.
Is there any other way that can utilized to embed activex control in silverlight app. I read somewhere that silverlight 4 has support for COM components. Can silverlight4 provide support for embedding activex control in a silverlight app.
Any help on this is highly appreciated and if some samples/documentation link is there that would be great.
Thanks in advance.
Silverlight does have support for COM automation servers like those used with Microsoft Office. It doesn't have general support for COM though and even if it did, ActiveX controls have very specific hosting requirements.
The idea of using the browser control is a possibility, but it will introduce some significant limitations. For one, you cant use the WebBrowser control in Silverlight unless you're running in out-of-browser mode which means your users would have to take steps to install the Silverlight application.
Additionally, the WebBrowser control (including any ActiveX controls it contains) will always render above your Silverlight content and won't be able to participate in transforms, animations, styling, etc. In other words it will stick out like a sore thumb.
What kind of control is it? Perhaps there is an alternative?

Guidelines for Sharing code between Silverlight and WPF

I want to share as much code as possible between Silverlight and WPF.
My lowest level handles the difference between calling the database directly and calling a web service.
My data layer on top of that is compiled with both .NET and Silverlight.
My GUI layer is currently designed as a WPF Control Library.
For sivlerlight...
Is it possible to reuse my XAML for my silverlight class library?
Do I need to create a "Silverlight Application" or can I just display controls from my class library directly?
What things do I need to be careful about? (For example, I already learned that Silverlight can't use DataTables in web service calls.)

Host a Silverlight application in Winforms application

I have a need to host a Silverlight application as a module in an existing WinForms application. My plan is to host the web page that hosts the Silverlight app in a web browser control in the WinForms application.
The part I have not been able to figure out is how to communicate from the Silverlight application back to the Winforms application. For starters, the Silverlight application needs to inform the web page that it is closing and have the browser control inform the WinForms module that the application has terminated. Once that is working I need to be able to send several different events to the WinForms program.
This does not seems like it should be hard to do, but I am hoping that someone can save me a lot of experimenting and keep me from wasting time following the wrong path.
My environment is Silverlight 4. The Winforms application also currently is hosting some WPF controls.
kind of a backwards approach.
Silverlight is a workaround to make WPF available on other platforms.
If you are running winforms, just host it as WPF window. It is really easy.
MyWindow window = new MyWindow(); // WPF widnow
ElementHost.EnableModelessKeyboardInterop(window) // this is part of windforms integration namespace, allows winforms and wpf to communicate
window.Show();

Resources