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

  • Home
  • SEARCH
  • 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 72957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:07:34+00:00 2026-05-10T20:07:34+00:00

I would like to host a silverlight control in winforms via a winforms browser,

  • 0

I would like to host a silverlight control in winforms via a winforms browser, but for it to work I need some way for the forms to talk to the silverlight, and also the other way around. Would it be possible to somehow have the two interact with each other using JavaScript as a middleman? I.e., have the form speak to the browser’s javascript, and have that speak to the silverlight control? Is there a better way? Or even a way at all? (other than compiling the code as silverlight and wpf)

  • 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. 2026-05-10T20:07:34+00:00Added an answer on May 10, 2026 at 8:07 pm

    I think using the Windows Forms WebBrowser control is your best bet. To do this, you’ll need your Silverlight app on a webpage, then you point your WebBrowser at the page’s URI.

    To keep your WebBrowser control from acting like IE, I’d recommend setting the following:

    webBrowser.AllowNavigation = false; webBrowser.AllowWebBrowserDrop = false; webBrowser.IsWebBrowserContextMenuEnabled = false; webBrowser.WebBrowserShortcutsEnabled = false; 

    Calling methods on your form from within Silverlight is easy enough to do. To start, you need a class that has all the methods you want to call from Silverlight. You can use your form itself or another object, but you need to mark the class with the [ComVisible(true)] attribute. Then you assign your object to the WebBrowser.ObjectForScripting property. This exposes your object as ‘window.external’ on the webpage.

    [ComVisible(true)] public partial class Form1 : Form {     ......     webBrowser.ObjectForScripting = this;     ......     public void CallMeInForm(string something)     {         MessageBox.Show('Silverlight said: ' + something);     } } 

    That’s it for inside your Windows Forms project. Inside of your Silverlight app, you need to pick up this ObjectForScripting and invoke methods on it. To call the method in my example above, use the following lines:

    using System.Windows.Browser; ...... ScriptObject myForm = (ScriptObject)HtmlPage.Window.GetProperty('external'); myForm.Invoke('CallMeInForm', 'testing 1 2 3'); 

    The Invoke command lets you pass any number and type of parameters to your function, although I suspect it wouldn’t like it very much if you try passing complex datatypes around. But if you needed to do so, you could always use serialization.

    Calling Silverlight functions from your form seems to be the tricker direction. I haven’t figured this one out completely yet.

    In your Silverlight app, you also expose functions to the webpage. To do this, use the HtmlPage.RegisterScriptableObject() function. Again, you can pass in any class with methods you want to expose. For a method to be exposed, though, you have to mark it with the [ScriptableMember] attribute.

    HtmlPage.RegisterScriptableObject('Page', this); ...... [ScriptableMember] public void CallMeInSilverlight(string message) {     HtmlPage.Window.Alert('The form said: ' + message); } 

    At this point, your method is exposed to JavaScript on the page and you could call it like so, assuming you added id='silverlightControl' to your <object> element:

    document.getElementById('silverlightControl').Content.Page.CallMeInSilverlight('testing 1 2 3'); 

    Notice the Page property? That’s what the call to RegisterScriptableObject() gave us. Now, let’s wrap this into a tidy JavaScript method:

    <script type='text/javascript'>     function CallMe(message) {         var control = document.getElementById('silverlightControl');         control.Content.Page.CallMeInSilverlight(message);     } </script> 

    And now we can call the CallMe() method from the Windows Forms app like so:

    public void CallToSilverlight() {     webBrowser.InvokeScript('CallMe', new object[] { 'testing 1 2 3' }); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 110k
  • Answers 110k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can actually use AppleScript to set breakpoints in XCode… May 11, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer See http://www.mysqludf.org/lib_mysqludf_xql/index.php for the lib_mysqludf_xql library from the MySQL UDF… May 11, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer See the multisample specification document: "If the depth test passes,… May 11, 2026 at 9:35 pm

Related Questions

I have a thick GUI application (possibly running as a service, but also just
The company where I work created this application which is core to our business
This sounds like a why would you do that? sort of question, but here
Yes, I know it is not the intention of Silverlight to host ASP.NET and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.