如何获得在Silverlight中效果很好的动画应用程序/代码,使其在WPF中也能正常工作? [英] How do I get animation appliaction/code that works great in Silverlight to work the same in WPF?

查看:78
本文介绍了如何获得在Silverlight中效果很好的动画应用程序/代码,使其在WPF中也能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现Silverlight仪表板演示非常有效@ http://blog.allaboutprogress.com/2010/04/silverlight-dashboards-part-i/

但是,我想让该应用程序在WPF中工作.我在Silverlight中创建了项目并使其运行,然后将文件复制到WPF应用程序中.

稍作调整后,我基本上以相同的方式使它工作,但是与Silverlight版本相比,动画看起来很糟糕.

1)在Silverlight中,无论表格大小如何,所有内容都可以顺畅地移动.在WPF中,当要进行大量动画处理时,动画会变得不稳定,并且在包含的窗口越大的情况下,效果也越差.

2)在Silverlight中,正在拖动的吊舱和需要采取这种方式的其他吊舱都可以平滑地进行动画处理.在wpf中,当您拖动鼠标时,要移动的容器不会移动,但是当您在周围拖动鼠标时,其他容器仍会移开.然后,当您释放鼠标时,吊舱会快速移动到实现鼠标的位置.此外,其他Pod的动画很快就可以看起来很不错(例如图形驱动程序不堪重负).

为什么对于wpf和silverlight之间的相同xaml和代码,其行为如此根本不同,又如何使WPF动画化原始Silverlight代码所具有的相同优美方式?

这是我必须进行的更改才能使用WPF版本.

因此,首先,我按照他们在Silverlight上所做的方式创建了所有内容,并在我第一次启动它时给了我一个错误:

I found Silverlight dashboard demo that works great @ http://blog.allaboutprogress.com/2010/04/silverlight-dashboards-part-i/

However, I want to get the application to work in WPF. I Created the Project in Silverlight and got it to run, then copied over the files into a WPF Application.

After a minor tweak I got it working, basically the same way, but the animation looks terrible compared to the Silverlight version.

1) In silverlight everything moves around smoothly no matter how large the form. In WPF animation gets erratic when there is to much animation going on, and also tends to perform worse the larger the containing window.

2) In Silverlight the both the pod that is being dragged and the other pods that need to get ot of the way animate smoothly. In wpf, the pod being moved does not move while you drag the mouse, but the other pods still get out of the way as you drag the mouse around. Then when you relase the mouse, the pod quickly move to the location you realeased the mouse at. Plus it doesn''t take long for the other pods'' animation to start looking bad (like the graphics driver is overwhelmed).

Why is the behavior so radically different for the same xaml and code between wpf and silverlight, and how can I get WPF to animate the same beautiful way the original Silverlight code does?

Here''s the change I had to make to get the WPF version to work.

So first I created everything the way they did it on the Silverlight and it gave me an error when I first started it:

{"''System.Windows.Media.Animation.DoubleAnimation'' cannot use default origin value of ''NaN''."}


因此,我通过更新方法进行了修复,


So, I fixed that by updating the method,

void TranslateAnimation(UIElement element, double newLeft, double newTop, double ts)

,方法开头有以下代码:

with follwoing code at the start of the method:

void TranslateAnimation(UIElement element, double newLeft, double newTop, double ts)
 {
  if (double.IsNaN(Canvas.GetLeft(element)))
  {
   element.SetValue(Canvas.LeftProperty, Convert.ToDouble(0));
  }

  if (double.IsNaN(Canvas.GetTop(element)))
  {
   element.SetValue(Canvas.TopProperty, Convert.ToDouble(0));
  }
  ...


这样就可以使代码启动/运行而不会崩溃.

此方法创建情节提要和Double动画对象,将其与吊舱挂钩,然后告诉情节提要开始.对于每个当前没有被鼠标拖动的移动Pod,它被循环调用一次.


This made it so the code would start/run without crashing.

This method creates the Storyboard and Double animation object, hooks it up with a pod, and then tells the storyboard to begin. It is called in a loop, once for each of the moving pods that that isn''t currently being dragged by the mouse.

推荐答案

我唯一知道的是告诉你的是,尽管WPF和Silverlight之间有相似之处,但它们仅应被视为表兄弟,而不是来自同一组父母的兄弟姐妹.我建议,如果要平滑WPF中的动画,则应使用google来在该平台上找到动画建议.
The only thing I know to tell you is that despite the similarities between WPF and Silverlight, they should only be considered as "cousins rather than siblings coming from the same set of parents. I recommend that if you want to smooth out the animations in WPF, you should use google to find animation advice for that platform.


这篇关于如何获得在Silverlight中效果很好的动画应用程序/代码,使其在WPF中也能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆