我試圖訪問屬性的RootVisual對象:訪問的Silverlight 3.0應用程序從JavaScript
[ScriptableType]
public class ApplicationInfo
{
public string Name { get; set; }
public string Version { get; set; }
}
[ScriptableType]
public partial class MainPage : UserControl
{
[ScriptableMember]
public ApplicationInfo ApplicationInfo { get; set; }
public MainPage()
{
InitializeComponent();
this.ApplicationInfo = new ApplicationInfo();
this.ApplicationInfo.Name = "My Application";
this.ApplicationInfo.Version = "0.1";
HtmlPage.RegisterScriptableObject("myapp", this);
}
}
在我的ASPX頁面主辦我下面的JavaScript片段:
<script type="text/javascript">
function onPluginLoaded(plugin) {
alert('in plugin');
alert(plugin.Name); //This gives me the x:Name of the RootVisual object
var appInfo = plugin.ApplicationInfo;
alert(appInfo);
alert(plugin.myapp);
document.title = appInfo.Name + " " + appInfo.Version;
}
</script>
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%" OnPluginLoaded="onPluginLoaded" >
<param name="source" value="ClientBin/SLVersion.xap"/>
<param name="onload" value="onPluginLoaded" />
這不起作用。我想知道爲什麼!提前致謝。
@Anthony:+1!感謝您的詳細回覆。從未聽說過getHost()!我在文檔中看到的所有內容都是get_elements():) MainPage上的[ScriptableType]是我的一廂情願!偉大的信息...我會嘗試確認...謝謝! – 2010-01-31 06:12:11
謝謝!有效! – 2010-02-01 23:38:23