摘要:Silverlight 2.0小技巧(11) JavaScript 呼叫xaml 內含數
本範例是JavaScript 呼叫Xmal 內的Msg 函數
*.Xmal
public Page()
{
InitializeComponent();
System.Windows.Browser.HtmlPage.RegisterScriptableObject("bridge", this);
}
[System.Windows.Browser.ScriptableMember]
public void Msg()
{
MessageBox.Show("Hello");
}
*.aspx
<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
<title>SilverlightApplication6</title>
<script type="text/javascript">
function msg() {
var SilverlightControl = document.getElementById("Xaml1");
SilverlightControl.content.bridge.Msg();
}
</script>
</head>
<body style="height:100%;margin:0;">
<form id="form1" runat="server" style="height:100%;">
<div style="height:100%;">
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightApplication6.xap"
MinimumVersion="2.0.31005.0" Width="100%" Height="100%" />
<input type="button" onclick="msg();" value="MssageBox" />
</div>
</form>
</body>
</html>