Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3930866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:17:52+00:00 2026-05-19T23:17:52+00:00

I have a WPF app. I need to embed a Silverlight app inside it.

  • 0

I have a WPF app. I need to embed a Silverlight app inside it. As I understand the most common way to do this is using of System.Windows.Controls.WebBrowser control (note: my app is wpf not WinForms).
BTW: there’s another way to host a Silverlight app – to use its COM interface (see http://www.codeproject.com/KB/atl/Host_Silverlight_In_ATL.aspx).

So in my WPF app I have a WebBrowser somewhere:

<WebBrowser x:Name="webBrowser">

where I load my html page (let’s assume local htlm page for the sake of simplicity):

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        webBrowser.LoadCompleted += WebBrowser_LoadCompleted;
        webBrowser.Navigate(new Uri(Path.GetFullPath("HostPage.htm")));
    }

    private void WebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
    {
        MessageBox.Show("Silverlight app has loaded");
    }

Ok. That’s easy.
Now I want to communicate with the host from the SL-app and with the SL-app from the host.

I understand technics for interoperability between HTML(JS) and Silverlight ( http://msdn.microsoft.com/en-us/library/cc645076%28VS.95%29.aspx ) and between .NET and JS inside WebBrowser.
I can set up WebBrowser.ObjectForScripting with an object (marked with ComVisibleAttribute) and the object will be accessing in JS.
I even can get reference to this object from my embedded Silverlight app:

(ScriptObject) HtmlPage.Window.GetProperty("external");

I also can make some object inside the Silverlight app visible to JS (and probably to host code) via HtmlPage.RegisterScriptableObject(“name”, anObject);

But. The problem is that in all cases I have to deal with some untyped ScriptObject instances.
But I’d like to set up “fully managed code” communication between the host and the SL-app. I mean passing complex structures/classes/delegates, raising event, and so on, i.e. without any “untyped JS-stuff”.

How can I do that?

UPDATE:
ok, it seems that there’s no nice way to do what I want.
So I have to deal with JS-interoperability. But here I have a problem.
From the host I set up ObjectForScripting and SL-app can use it. That means the SL-app gets results from methods of the object set up in WebBrowser.ObjectForScripting:

((ScriptObject) HtmlPage.Window.GetProperty("external")).Invoke("methodName")

But not on the contrary.
In my SL-app I register an object (of type BridgeSl):

m_bridgeSl = new BridgeSl();
HtmlPage.RegisterScriptableObject("bridge", m_bridgeSl);

Then create JS-function in html :

<script type="text/javascript">
var g_bridgeSl = null;
function pluginLoaded(sender, args) {
    g_bridgeSl = sender.getHost().Content.bridge;
}
</script>

where pluginLoaded is handler of the SL plugin’s onLoad event:

<object id="slCtrl" data="data:application/x-silverlight-2," type="application/x-silverlight-2" ...>
  <param name="onLoad" value="pluginLoaded" />
</object>

Then add function returning this object:

function getBridge() {
  return g_bridgeSl;
}

I did all this stuff as I hoped that I can get BridgeSl’s instance inside my host app:

var bridgeSl = WebBrowser.InvokeScript("getBridge");

Actually I get something. It’s an instance of “System.__ComObject”. But when I cast it to dynamic:

dynamic dynBridgeSl = bridgeSl;

I get System.SystemException object with message “The method or operation is not implemented”. Ok, it’s can’t be treated as a dynamic, but what is it then? How to invoke any method on it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:17:52+00:00Added an answer on May 19, 2026 at 11:17 pm

    There’s no managed-only interop at this time. The two options you mention (JavaScript interop over the DOM bridge, or COM hosting) are all that exists.

    I do commend you for doing your research – you knew everything I was going to say when I clicked on the question!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an interesting conundrum. We have a WPF app that has a Vista-like
I'm creating a WPF app and have a system tray icon with a context
I have a Windows Forms app, that has a single ElementHost containing a WPF
I have a WPF app in which I need to programatically manipulate at runtime.
I have a wpf app with a combobox like this <ComboBox name=cmbBx1> <ComboBoxItem Name=Jan>January</ComboBoxItem>
I am writing an app using WPF 3.5 and I need twitter integration. I
I need in wpf app check messages on server. I have own method which
I have successfully rendered my test report using Winforms.ReportViewer in WPF app.... Now I
I have a very interesting problem. I use this technologies in WPF app: Caliburn.Micro
I have a .NET based (WPF) app which crashes on Windows XP Service Pack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.