silverlight后台代码:
using System.Windows.Browser;
public Page1()
{
HtmlPage.RegisterScriptableObject("PageModel", this);
InitializeComponent();
}
[ScriptableMember()]
public void SetMargin(long left, long top, long right, long bottom)
{
Thickness margin = new Thickness(left, top, right, bottom);
this.控件名称.Margin = margin;
}
js 代码:
function setMargin() {
var silverlight = document.getElementById("silverlight"); // 引用silverlight的object
silverlight.Content.PageModel.SetMargin(1, 2, 3, 4); // js调用silverlight方法
}