silverlight与JavaScript交互,WebApplication在哪里?
RT,找不到WebApplication啊,使用WebApplication.Current.RegisterScriptableObject后,
显示:找不到类型或命名空间名称“WebApplication”(是否缺少 using 指令或程序集引用?)
请问如何才能使用这个类啊~
[解决办法]
使用 [Scriptable] 属性了么?
试试这样写代码:
using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using System.Windows.Browser;namespace ClientSideAndServerSide { [Scriptable] public class EventArgs<T> : EventArgs { private T _data; public EventArgs(T args) { _data = args; } [Scriptable] public T Data { get { return _data; } } } [Scriptable] public partial class Page : Canvas { [Scriptable] public event EventHandler CallbackToBrowser; public void Page_Loaded(object o, EventArgs e) { // Required to initialize variables InitializeComponent(); WebApplication.Current.RegisterScriptableObject("EntryPoint", this); this.MouseLeftButtonDown += new MouseEventHandler(Page_MouseLeftButtonDown); } void Page_MouseLeftButtonDown(object sender, MouseEventArgs e) { if (CallbackToBrowser != null) { CallbackToBrowser(this, new EventArgs<string>("my value")); } } }}