WEB开发网
开发学院图形图像Flash Silverlight(27) - 2.0网页之可脚本化, 与DOM的交... 阅读

Silverlight(27) - 2.0网页之可脚本化, 与DOM的交互, 与JavaScript的交互

 2009-02-16 11:57:05 来源:WEB开发网   
核心提示: ScriptableDemo.xaml.csusing System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.

ScriptableDemo.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
  
using System.Windows.Browser;
  
namespace Silverlight20.WebPage
{
  public partial class ScriptableDemo : UserControl
  {
    System.Threading.Timer _timer;
    System.Threading.SynchronizationContext _syncContext;
  
    public ScriptableDemo()
    {
      InitializeComponent();
  
      this.Loaded += new RoutedEventHandler(ScriptableDemo_Loaded);
    }
  
    void ScriptableDemo_Loaded(object sender, RoutedEventArgs e)
    {
      // UI 线程
      _syncContext = System.Threading.SynchronizationContext.Current;
  
      Scriptable s = new Scriptable() { CurrentTime = DateTime.Now };
  
      // 将 Scriptable 对象注册到客户端中,所对应的客户端的对象名为 scriptable
      HtmlPage.RegisterScriptableObject("scriptable", s);
  
      _timer = new System.Threading.Timer(MyTimerCallback, s, 0, 1000);
    }
  
    private void MyTimerCallback(object state)
    {
      Scriptable s = state as Scriptable;
  
      // 每秒调用一次 UI 线程上的指定的方法
      _syncContext.Post(OnStart, s);
    }
  
    void OnStart(object state)
    {
      Scriptable s = state as Scriptable;
  
      // 调用 Scriptable 对象的 OnStart() 方法,以触发 Start 事件
      s.OnStart(DateTime.Now);
    }
  }
}

上一页  1 2 3 4 5 6 7  下一页

Tags:Silverlight 网页 脚本

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接