稳扎稳打Silverlight(1) - 1.0实例之电子表

本文介绍如何使用Silverlight 1.0创建一个简单的客户端电子表应用,展示了如何获取系统时间并实时更新显示。通过XAML和JavaScript实现了时间的动态展示,并包含了鼠标交互效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

导读:
  [源码下载]
  稳扎稳打Silverlight(1) - 1.0实例之电子表
  作者:webabcd
  介绍
  用Silverlight 1.0实现一个基于客户端系统时间的电子表。
  参考:http://silverlight.net/community/communitygallery.aspx
  示例
  Clock.xaml(用Expression Blend开发)
  
  
  
<  
  
  xmlns="http://schemas.microsoft.com/client/2007"
  
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  
  Width="180" Height="150"
  
  Background="#0030628D"
  
  x:Name="Page" Loaded="enableClock"
  
  >
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

  Clock.xaml.js
  
  
  if (!window.Clock)
  
  
  
  
  window.Clock =
  
  {}
  
  
  
  Clock.Page = function()
  
  
  
  
  
  {
  
  
  }
  
  
  
  Clock.Page.prototype =
  
  
  
  
  
  {
  
  
  handleLoad: function(control, userContext, rootElement)
  
  
  
  
  
  
  {
  
  
  this.control = control;
  
  
  
  
  
  // Sample event hookup:
  
  rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
  
  
  },
  
  
  
  
  
  // Sample event handler
  
  handleMouseDown: function(sender, eventArgs)
  
  
  
  
  
  
  {
  
  
  // The following line of code shows how to find an element by name and call a method on it.
  
  // this.control.content.findName("Timeline1").Begin();
  
  }
  
  }
  
  
  
  // TextBlock的MouseLeftButtonDown调用的方法
  
  function MouseLeftButtonDown(sender, args)
  
  
  
  
  
  {
  
  
  window.open("http://webabcd.cnblogs.com");
  
  
  }
  
  
  
  // TextBlock的MouseMove调用的方法
  
  function MouseMove(sender, args)
  
  
  
  
  
  {
  
  
  // TextBlock.foreground
  
  sender.foreground = "red"
  
  // TextBlock.textDecorations
  
  sender.textDecorations = "underline"
  
  }
  
  
  
  // TextBlock的MouseLeave调用的方法
  
  function MouseLeave(sender, args)
  
  
  
  
  
  {
  
  
  // TextBlock.foreground
  
  sender.foreground = "#FF100888"
  
  // TextBlock.textDecorations
  
  sender.textDecorations = "none"
  
  }
  Default.aspx
  
  
  
  
  <%
<  
  @ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs"
  
  Inherits="_10_Clock_Default" Title="电子表" %>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

  
  
  
  
  
  
  
  
  
  

  
  
  
  
  Default.aspx.js
  
  
  function createSilverlight()
  
  
  
  
  
  {
  
  
  var scene = new Clock.Page();
  
  
  
  
  Silverlight.createObjectEx(
  
  {
  
  
  source: "Clock.xaml",
  
  
  parentElement: document.getElementById("SilverlightControlHost"),
  
  
  id: "SilverlightControl",
  
  
  
  
  properties:
  
  {
  
  
  width: "100%",
  
  
  height: "100%",
  
  
  version: "1.0"
  
  },
  
  
  
  
  events:
  
  {
  
  
  onLoad: Silverlight.createDelegate(scene, scene.handleLoad)
  
  
  }
  
  });
  
  
  }
  
  
  
  
  
  if (!window.Silverlight)
  
  
  
  
  window.Silverlight =
  
  {}
  
  
  
  
  
  Silverlight.createDelegate = function(instance, method)
  
  {
  
  
  
  
  return function()
  
  {
  
  
  return method.apply(instance, arguments);
  
  
  }
  
  }
  Clock.js
  
  
  // date.getDay()索引转文字
  
  var aryWeek = new Array(7)
  
  
  aryWeek[0]="Sun"
  
  aryWeek[1]="Mon"
  
  aryWeek[2]="Tue"
  
  aryWeek[3]="Wed"
  
  aryWeek[4]="Thu"
  
  aryWeek[5]="Fri"
  
  aryWeek[6]="Sat"
  
  
  
  // date.getMonth()索引转文字
  
  var aryMonth = new Array(12)
  
  
  aryMonth[0]="01"
  
  aryMonth[1]="02"
  
  aryMonth[2]="03"
  
  aryMonth[3]="04"
  
  aryMonth[4]="05"
  
  aryMonth[5]="06"
  
  aryMonth[6]="07"
  
  aryMonth[7]="08"
  
  aryMonth[8]="09"
  
  aryMonth[9]="10"
  
  aryMonth[10]="11"
  
  aryMonth[11]="12"
  
  
  
  // Canvas的Loaded调用的方法
  
  function enableClock()
  
  
  
  
  
  {
  
  
  var date = new Date();
  
  
  
  
  var SilverlightControl = document.getElementById("SilverlightControl");
  
  
  
  
  // plugin.content.findName(objectName)
  
  var hour = SilverlightControl.content.findName("txtHour");
  
  
  var minute = SilverlightControl.content.findName("txtMinute");
  
  
  var second = SilverlightControl.content.findName("txtSecond");
  
  
  var month = SilverlightControl.content.findName("txtMonth");
  
  
  var day = SilverlightControl.content.findName("txtDay");
  
  
  var week = SilverlightControl.content.findName("txtWeek");
  
  
  
  
  // TextBlock.text
  
  if (date.getHours() > 9)
  
  
  hour.text = date.getHours().toString();
  
  
  else
  
  hour.text = "0" + date.getHours().toString();
  
  
  
  
  if (date.getMinutes() > 9)
  
  
  minute.text = date.getMinutes().toString();
  
  
  else
  
  minute.text = "0" + date.getMinutes().toString();
  
  
  
  
  
  if (date.getSeconds() > 9)
  
  
  second.text = date.getSeconds().toString();
  
  
  else
  
  second.text = "0" + date.getSeconds().toString();
  
  
  
  
  
  month.text = aryMonth[date.getMonth()];
  
  
  
  
  
  if (date.getDate() > 9)
  
  
  day.text = date.getDate().toString();
  
  
  else
  
  day.text = "0" + date.getDate().toString();
  
  
  
  
  
  week.text = aryWeek[date.getDay()];
  
  
  
  
  
  setTimeout("enableClock()",1000);
  
  
  }
  
  
  
  // 全屏(TextBlock的MouseLeftButtonDown调用的方法)
  
  function toggle_fullScreen(sender, args)
  
  
  
  
  
  {
  
  
  // 当前元素所属的Silverlight插件
  
  var silverlightPlugin = sender.getHost();
  
  
  silverlightPlugin.content.fullScreen = !silverlightPlugin.content.fullScreen;
  
  
  }
  OK
  [源码下载]

本文转自
http://www.cnblogs.com/webabcd/archive/2007/09/17/895328.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值