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…
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值