演练:使用 Expression Blend 或代码创建 Silverlight 时钟
2009-04-18 22:28
555 查看
Code
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;
namespace SilverlightClock
{
public partial class Page : UserControl
{
public Page()
{
// Required to initialize variables
InitializeComponent();
Loaded += new RoutedEventHandler(SetAndStartClock);
}
private void SetAndStartClock(object sender, EventArgs e)
{
// The current date and time.
System.DateTime currentDate = DateTime.Now;
// Find the appropriate angle (in degrees) for the hour hand
// based on the current time.
double hourangle = (((float)currentDate.Hour) / 12) * 360 + currentDate.Minute / 2;
// The same as for the minute angle.
double minangle = (((float)currentDate.Minute) / 60) * 360;
// The same for the second angle.
double secangle = (((float)currentDate.Second) / 60) * 360;
// Set the beginning of the animation (From property) to the angle
// corresponging to the current time.
hourAnimation.From = hourangle;
// Set the end of the animation (To property)to the angle
// corresponding to the current time PLUS 360 degrees. Thus, the
// animation will end after the clock hand moves around the clock
// once. Note: The RepeatBehavior property of the animation is set
// to "Forever" so the animation will begin again as soon as it completes.
hourAnimation.To = hourangle + 360;
// Same as with the hour animation.
minuteAnimation.From = minangle;
minuteAnimation.To = minangle + 360;
// Same as with the hour animation.
secondAnimation.From = secangle;
secondAnimation.To = secangle + 360;
// Start the storyboard.
clockStoryboard.Begin();
}
}
}
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;
namespace SilverlightClock
{
public partial class Page : UserControl
{
public Page()
{
// Required to initialize variables
InitializeComponent();
Loaded += new RoutedEventHandler(SetAndStartClock);
}
private void SetAndStartClock(object sender, EventArgs e)
{
// The current date and time.
System.DateTime currentDate = DateTime.Now;
// Find the appropriate angle (in degrees) for the hour hand
// based on the current time.
double hourangle = (((float)currentDate.Hour) / 12) * 360 + currentDate.Minute / 2;
// The same as for the minute angle.
double minangle = (((float)currentDate.Minute) / 60) * 360;
// The same for the second angle.
double secangle = (((float)currentDate.Second) / 60) * 360;
// Set the beginning of the animation (From property) to the angle
// corresponging to the current time.
hourAnimation.From = hourangle;
// Set the end of the animation (To property)to the angle
// corresponding to the current time PLUS 360 degrees. Thus, the
// animation will end after the clock hand moves around the clock
// once. Note: The RepeatBehavior property of the animation is set
// to "Forever" so the animation will begin again as soon as it completes.
hourAnimation.To = hourangle + 360;
// Same as with the hour animation.
minuteAnimation.From = minangle;
minuteAnimation.To = minangle + 360;
// Same as with the hour animation.
secondAnimation.From = secangle;
secondAnimation.To = secangle + 360;
// Start the storyboard.
clockStoryboard.Begin();
}
}
}
相关文章推荐
- [演练]使用Expression Blend或代码创建Silverlight时钟
- [演练]使用Expression Blend或代码创建Silverlight时钟
- MSDN中“演练:使用 Web 窗体页创建分页的数据访问” 一文中的代码的一点改进
- [Silverlight]通过SilverlightLoader使用托管代码创建自定义载入界面(Splash Screen) (上)
- 写了一个使用代码创建Silverlight的函数
- 精通Silverlight——12.6.1 使用.NET代码创建控件
- 创建数据库后支持的模型被更改,考虑使用代码优先更新数据库
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- 演练:使用 Microsoft Expression Blend 创建按钮
- 使用少于500行的代码创建一个webserver
- SSM框架——使用MyBatis Generator自动创建代码
- [Cocoa]使用代码创建窗口
- 使用代码自动创建模型属性
- QT中静态库的生成与使用——创建共享库代码,附例子
- [转]使用新的代码和标记模型创建真实的应用程序
- 使用代码动态创建Selector
- 手把手教你使用Silverlight实现3D场景二(创建自定义模版控件为物件应用3D动画)
- 使用 UITableView 创建表格应用演练(4)——自定义单元格
- 如何使用VS创建SharePoint自定义Ribbon菜单(图文和代码)
- 使用 JavaScript 创建可维护的幻灯片效果代码第1/3页