首页 > 代码库 > WPF区时浏览小程序
WPF区时浏览小程序
在深圳已经工作了一个月了,之前做WinForm的,现在做WPF,每天加班到晚上10点,比之前累。学习新技术也是有个过程的,我就从基础的语法和
界面布局做起。这是我仿着做一个小软件。
效果图赏析
在原基础上增加了一个树叶飘动的效果。
主要代码如下:
1 <Canvas.Triggers> 2 <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 3 <BeginStoryboard> 4 <Storyboard Storyboard.TargetName="img1" Storyboard.TargetProperty="(Canvas.Left)"> 5 <DoubleAnimation From="0" To="514" Duration="0:0:20" RepeatBehavior="23:59:59" AutoReverse="True"/> 6 </Storyboard> 7 </BeginStoryboard> 8 <BeginStoryboard Storyboard="{StaticResource StoryboardLeaf}"/> 9 </EventTrigger>10 </Canvas.Triggers>
树叶漂动 KeyTime="0" Value="http://www.mamicode.com/0"起始位置 KeyTime="0:0:2" Value="http://www.mamicode.com/20"转动的时间和角度(顺时针) KeyTime="0:0:4" Value="http://www.mamicode.com/0"最后
的状态
1 <Storyboard x:Key="StoryboardLeaf" RepeatBehavior="Forever">2 <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)3 4 [1].(RotateTransform.Angle)" Storyboard.TargetName="bd">5 <EasingDoubleKeyFrame KeyTime="0" Value="0"/>6 <EasingDoubleKeyFrame KeyTime="0:0:2" Value="20"/>7 <EasingDoubleKeyFrame KeyTime="0:0:4" Value="0"/>8 </DoubleAnimationUsingKeyFrames>9 </Storyboard>
1 this.ShowInTaskbar = false;//是否在任务栏显示
1 timer = new DispatcherTimer();//按时间间隔处理的类2 timer.Interval = TimeSpan.Parse("00:00:01");//时间刻度的时间间隔,默认是00:00:003 timer.IsEnabled = true;4 timer.Tick += new EventHandler(timer_Tick);//DispatcherTimer.Tick超过计时间隔时发生
1 BitmapImage dayOrNight = new BitmapImage();//建一张图片 2 dayOrNight.BeginInit(); 3 string uri = "pack://application:,,,/WpfTimeZoneExample;component/Images/"; 4 int nowHour = Int32.Parse(DateTime.Now.ToString("HH")); 5 if (nowHour >= 6 && nowHour <=18) 6 { 7 uri += "sun2.png"; 8 DayMark.Width = 105; 9 DayMark.Height = 53;10 }11 else12 {13 uri += "moon.png";14 DayMark.Width = 50;15 DayMark.Height = 50;16 }17 dayOrNight.UriSource = new Uri(uri);//设置源18 dayOrNight.EndInit(); 19 DayMark.Source = dayOrNight;
1 private void timer_Tick(object sender,EventArgs e)2 {3 CNT.Text = DateTime.Now.ToString("HH:mm:ss");4 UST.Text = DateTime.Now.AddHours(-12).ToString("HH:mm:ss");5 UKT.Text = DateTime.Now.AddHours(-7).ToString("HH:mm:ss");6 PRT.Text = DateTime.Now.AddHours(-6).ToString("HH:mm:ss");7 SNT.Text = DateTime.Now.AddHours(2).ToString("HH:mm:ss");8 BXT.Text = DateTime.Now.AddHours(-11).ToString("HH:mm:ss");9 }
1 private void Grid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)2 {3 this.DragMove();//拖拽4 }
鼠标放上去时,太阳/月亮 升降
1 private void DayMark_MouseEnter(object sender, MouseEventArgs e)2 {3 TranslateTransform trans = new TranslateTransform();//TransformGroup4 DayMark.RenderTransform = trans;//设置平移的对象5 DoubleAnimation animation = new DoubleAnimation(15, TimeSpan.FromSeconds(1));//15为目标值,后一个参数是动画持续时间6 animation.AutoReverse = true;//是否以相反的顺序播放7 trans.BeginAnimation(TranslateTransform.YProperty, animation);//TranslateTransform.YProperty,沿X,Y移动的属性。BeginAnimation应用动画8 }
最后说明一下,本程序开发环境:VS2013 运行环境:.Net4.5 源码下载:区时浏览小程序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。