After a list, you have to use Silverlight 5来 to make a project, never touching this thing before, for work. It's up to you to bite the bullet. Groping for a night, big to sort out some of the items required in the following as a preliminary record:
Silverlight 5 How to talk to JavaScript
Silverlight 5 belongs to the client, and the client is communicating with the server, and the first thing I think about is the JavaScript-based Ajax adhesive. So start by interacting with JavaScript from Silverlight 5.
One, Silverlight 5 speaks, JavaScript listens
从Silverlight 5里向Javascript发送程序执行请求。
Silverlight 5端代码详细例如以下:
HtmlPage.Window.Invoke("Javascript函数方式""传值-Oyiboy");
The code above is able to execute JavaScript script code directly in Silverlight 5 and send the necessary data out.
Second, JavaScript to speak. Silverlight 5 Listen
Javascript使用ajax获取server端数据后发送给Silverlight 5,以达到Silverlight 5与server端的交互效果。
Silverlight 5端代码详细例如以下:
//设置值 [ScriptableMember()]//这行是关键。必须有这个javascript才干请求到这种方法 publicvoidsetVal(string D) { this.textView.Text = D; } //javascript主动要求返回值 [ScriptableMember()] publicstringreturnVal() { returnthis.textView.Text; }
Html代码调整:须要在Silverlight 5插件的object代码内里加入下面參数设置句。以达到插件在载入后获取siliverlight对象。
<param name="onLoad"value="siliverLoaded" />
Javascript代码详细例如以下:
//siliverlight Object varSiliverlightobj =NULL;//The Silverlight 5 onload event-triggered function set in the above HTML code function siliverloaded(sender, args) {Siliverlightobj = Sender.gethost (); }//The. Buttonset and. Buttonreu in the code below are two buttons with these class. The button won't be written out in detail. //This is the Setval method that executes within Silverlight 5$(". Buttonset"). Click ( function () {SiliverlightObj.Content.Main.setVal ("JavaScript passed in value-oyiboy"); })//This is the ReturnVal method that executes within Silverlight 5$(". Buttonreu"). Click ( function () {Alert (SiliverlightObj.Content.Main.returnVal ()); });
The above several ways, the flexible use of live basically completely conquer the Silverlight 5 and server side of the communication between, OK, although this article of the topic is Silverlight 5 and JavaScript. But finally the goal is Silverlight 5 and server side of the interaction, anyway Ajax is not a new thing, so it skipped.
Sentiment: Through the Silverlight 5 object SiliverlightObj.Content.Main this big channeling thing to see, Siliverlightobj still can do a lot of other things, detailed also must slowly grope, suppose later have need to use words. may also be out of this explanatory article, perhaps.
2015-07-10 Trap:
Main in SiliverlightObj.Content.Main refers to the name of the interview in the Application_Startup event App.xaml in Silverlight, with detailed code such as the following:
privatevoidApplication_Startup(object sender, StartupEventArgs e) { thisnew MainPage(); System.Windows.Browser.HtmlPage.RegisterScriptableObject("Main"this.RootVisual); }
From the code. Suppose there are multiple XAML pages. Just to register a different name here is to be able to refer to a JavaScript method that is declared within a different XAML page.
Just tidy up the code in App.xaml found this code just remember to give this to leak, today to fill back.
A preliminary study of Silverlight 5 (C #)