Wpf跳跃的篮球
抛砖引玉,旨在如何wpf如何全屏,如何动态载入控件、图片等,如何设置简单的动画。
万恶的csdn上传系统,即不能修改自己上传的对象,还要积分。
http://code.google.com/p/wpf-fullscreen-animation/downloads/list
using System;using System.Windows;using System.Windows.Controls;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Media.Animation;//动画所在的namespacenamespace FullScreen{ /// <summary> /// 篮球有拖尾,待解决 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainWindow_Loaded); this.KeyUp += new KeyEventHandler(MainWindow_KeyUp); double height = SystemParameters.PrimaryScreenHeight; double width = SystemParameters.PrimaryScreenWidth; /*/动画****************************************/ DoubleAnimation daX = new DoubleAnimation(); daX.AutoReverse = true; daX.RepeatBehavior = RepeatBehavior.Forever; daX.From = 0d; daX.To= width-85; DoubleAnimation daY = new DoubleAnimation(); daY.AutoReverse = true; daY.RepeatBehavior = RepeatBehavior.Forever; daY.From = 0d; daY.To= height-85; Duration duration = new Duration(TimeSpan.FromSeconds(5)); daX.Duration=duration; daY.Duration =duration; BounceEase be = new BounceEase(); be.Bounces = 5; be.Bounciness = 3; //daX.EasingFunction = be; daY.EasingFunction = be;//设定y方向的弹跳 /***************************************************/ Label l = new Label(); l.Height = l.Width = 80; l.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; l.VerticalAlignment = System.Windows.VerticalAlignment.Top; l.Margin = new Thickness(0); //l.Background = new SolidColorBrush(Colors.Violet); l.Background = new ImageBrush(new BitmapImage(new Uri("basketball.png",UriKind.Relative))); l.RenderTransform = new TranslateTransform(); l.RenderTransform.BeginAnimation(TranslateTransform.XProperty, daX); l.RenderTransform.BeginAnimation(TranslateTransform.YProperty, daY); Grid.SetColumn(l, 0); Grid.SetRow(l, 0); grid1.Children.Add(l); //Image image =new Image(); //BitmapImage bi = new BitmapImage(new Uri("basketball.png",UriKind.Relative)); //image.Source = bi; //image.Width = 80; //image.Height = 80; //image.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; //image.VerticalAlignment = System.Windows.VerticalAlignment.Top; //image.Margin = new Thickness(0); ////image.RenderTransform.BeginAnimation(TranslateTransform.XProperty, daX); ////image.RenderTransform.BeginAnimation(TranslateTransform.YProperty, daY); //Grid.SetRow(image, 0); //Grid.SetColumn(image, 0); //grid1.Children.Add(image); } void MainWindow_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) this.Close(); } void MainWindow_Loaded(object sender, RoutedEventArgs e) { // 设置全屏 this.WindowState = System.Windows.WindowState.Normal; this.WindowStyle = System.Windows.WindowStyle.None; this.ResizeMode = System.Windows.ResizeMode.NoResize; this.Topmost = true; this.Background = new SolidColorBrush(Colors.LightGreen); this.Left = 0.0; this.Top = 0.0; this.Width = System.Windows.SystemParameters.PrimaryScreenWidth; this.Height = System.Windows.SystemParameters.PrimaryScreenHeight; } }}