Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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));
  }
  ...

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.
Posted
Comments
Mark Salsbery 2-Jul-11 12:38pm    
"Convert.ToDouble(0)"?? :) I'm just curious....are you running in the debugger? Is the performance the same running the app stand-alone?
snowdogs2 5-Jul-11 10:51am    
Yes I was running in debugger, but I've also built a realease version and run that on it's own as well as run without debug and the performance was equally poor. I did however find out that getting rid of the drop shadow effect drastically improves the performance, to acceptable levels. However, Once I start putting things in my pods to make it a practical dashboard I'm concerned that it will start chugging again, because if a drop shadow effect works fine in silverlight and causes WPF to come to a crashing halt, there's no telling what will break WPF.

I've also noticed that most WPF applications have some kind of Framerate issue. When you drag to resize there is a visible black edge along the right and bottom that appears while you resize. It's not just my application, I downloaded a demo on basic animation timing and it has the same effect. However, if I create a default WPF application, with nothing in it resizes without the black shadow. It's seems certain graphic events require more of the system and cause it to slow down. However, I have no idea what causes what to crash and burn. I did a test with the original Silverlight and it has a similar issue with the edge as you resize, but again no issue with the DropShadow. There seems to be some very odd discrepincies in performance, that don't make a lot of sense. One effect works fine in Silverlight, and causes the animation to grind to a halt in WPF. How are to know what effects, settings, overwhelm the animation, in which system. I looked in MSDN on wpf animation tips and tricks, and I didn't see anything the about DropShadow effects, or any settings/effects causing problems.

Finally, as for the Convert.ToDouble, yeah, that was an original draft, I've since changed to "0.0". the TopPropert was being set to null by default in WPF, and had to be set back to 0. There are a number of little quirk differences that I've been noticing that don't quite translate to WPF.

Finally as for the Conver.ToDouble(0), yeah, it was from a first draft. I've since replaced it with 0.0. The Canvas.Top and LeftProperties were being set to Null when moved over to WPF. Took a little while to figure that out, as the exception wasn't pointing right there. I've found a number of little quirky differences when moving from Silverlight to WPF.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900