WPF,后台处理耗时任务,前台显示等待动画Demo

eHuaTian 2015-02-28 12:32:10
WPF,后台处理耗时任务,前台显示等待动画Demo(动画效果可以仿Win8等待效果)。急求可测试可以运行的代码。
...全文
1821 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
稀饭_RD 2015-03-12
  • 打赏
  • 举报
回复
private void Init3() { Button btn=new Button(); btn.Name="ThreadButton"; btn.Content="异步动画"; btn.Click+=new RoutedEventHandler(btn_click); Canvas.SetTop(btn, 100); Canvas.SetZIndex(btn, 0); board.Children.Add(btn); } void btn_click(object sender, EventArgs e) { // 你的动画控件 Canvas cv = new Canvas(); cv.Width = this.ActualWidth; cv.Height = this.ActualHeight; cv.Visibility = System.Windows.Visibility.Hidden; cv.Background = Brushes.Silver; Rectangle rt = new Rectangle(); rt.Width = rt.Height = 50; rt.Fill = Brushes.Red; cv.Children.Add(rt); Canvas.SetTop(rt, 0); Canvas.SetLeft(rt, 0); cv.MouseLeftButtonDown += new MouseButtonEventHandler(cv_MouseLeftButtonDown); Canvas.SetZIndex(cv, 10); board.Children.Add(cv); System.Threading.Thread td = new System.Threading.Thread ( new System.Threading.ParameterizedThreadStart(s =>{ // TODO Background Work System.Threading.Thread.Sleep(2000); this.Dispatcher.BeginInvoke( new System.Threading.ThreadStart(delegate() { cv.Visibility = System.Windows.Visibility.Hidden; })); }) ); td.Start(); cv.Visibility = System.Windows.Visibility.Visible; } void cv_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Canvas cv = sender as Canvas; Rectangle rt = cv.Children[0] as Rectangle; Point pt = e.GetPosition(cv); Storyboard storyboard = new Storyboard(); DoubleAnimation doubleAnimationX = new DoubleAnimation(Canvas.GetLeft(rt),pt.X, new Duration(TimeSpan.FromMilliseconds(200))); Storyboard.SetTarget(doubleAnimationX, rt); Storyboard.SetTargetProperty(doubleAnimationX, new PropertyPath("(Canvas.Left)")); storyboard.Children.Add(doubleAnimationX); DoubleAnimation doubleAnimationY = new DoubleAnimation(Canvas.GetTop(rt), pt.Y, new Duration(TimeSpan.FromMilliseconds(200))); Storyboard.SetTarget(doubleAnimationY, rt); Storyboard.SetTargetProperty(doubleAnimationY, new PropertyPath("(Canvas.Top)")); storyboard.Children.Add(doubleAnimationY); storyboard.Begin(); }
eHuaTian 2015-03-03
  • 打赏
  • 举报
回复
能不能来段实在的代码
灬浪子灬 2015-02-28
  • 打赏
  • 举报
回复
异步

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧