Silverlight与HTML双向交互
生活随笔
收集整理的這篇文章主要介紹了
Silverlight与HTML双向交互
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Silverlight具備很好的用戶體驗,但有時需要在頁面的布局上進行特殊處理,比如作為webpart集成到Sharepoint中等等。
HTML和Silverlight之間的雙向交互可以更靈活的使用Silverlight進行開發,上午摸索了一下,記錄在此。
一,向Silverlight傳遞數據,實現個性化加載
Silverlight在HTML中的引用是:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/VideoCenter.xap"/> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="4.0.50401.0" /> <param name="autoUpgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none"> <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/> </a> </object> <param name="initParams" value="CategoryId=1" /> private void Application_Startup(object sender, StartupEventArgs e) { if (e.InitParams.Count != 0) { foreach(var item in e.InitParams) { this.Resources.Add(item.Key, item.Value); } } this.RootVisual = new MainPage(); } if(App.Current.Resources["CategoryId"]!=null) { int cateId = int.Parse(App.Current.Resources["CategoryId"].ToString()); CategoryItem c = new CategoryItem(); c.CategoryID = cateId; this.gridOfList.Children.Add(c); }二,Silverlight調用HTML中的腳本資源,實現自身的樣式等修改
function InvokePlayer(videoId) { document.getElementById("divCategory").style.display = "none"; var player = document.getElementById("divPlayer"); player.style.width = "100%"; player.style.height = "600px"; } System.Windows.Browser.HtmlPage.Window.Invoke("InvokePlayer", videoId); (HtmlPage.Window.GetProperty("InvokePlayer") as ScriptObject)InvokeSelf("Good Function!"); HtmlPage.Window.Eval("document.getElementById('result')") as HtmlElement… ??
? ? ?本文轉自wengyuli 51CTO博客,原文鏈接:http://blog.51cto.com/wengyuli/586516,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的Silverlight与HTML双向交互的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对CAML查询语句的几点小记
- 下一篇: ASP.NET Core MVC 模型绑