tags:

views:

560

answers:

5

I might be missing something really obvious. I'm trying to write a custom Panel where the contents are laid out according to a couple of dependency properties (I'm assuming they have to be DPs because I want to be able to animate them.)

However, when I try to run a storyboard to animate both of these properties, Silverlight throws a Catastophic Error. But if I try to animate just one of them, it works fine. And if I try to animate one of my properties and a 'built-in' property (like Opacity) it also works. But if I try to animate both my custom properties I get the Catastrophic error.

Anyone else come across this?

edit:

The two DPs are ScaleX and ScaleY - both doubles. They scale the X and Y position of children in the panel. Here's how one of them is defined:

 public double ScaleX
 {
  get { return (double)GetValue(ScaleXProperty); }
  set { SetValue(ScaleXProperty, value); }
 }

 /// <summary> 
 /// Identifies the ScaleX dependency property.
 /// </summary> 
 public static readonly DependencyProperty ScaleXProperty =
    DependencyProperty.Register(
       "ScaleX",
       typeof(double),
       typeof(MyPanel),
       new PropertyMetadata(OnScaleXPropertyChanged));

 /// <summary>
 /// ScaleXProperty property changed handler. 
 /// </summary>
 /// <param name="d">MyPanel that changed its ScaleX.</param>
 /// <param name="e">DependencyPropertyChangedEventArgs.</param> 
 private static void OnScaleXPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
  MyPanel _MyPanel = d as MyPanel;
  if (_MyPanel != null)
  {
   _MyPanel.InvalidateArrange(); 
  }
 }

 public static void SetScaleX(DependencyObject obj, double val)
 {
  obj.SetValue(ScaleXProperty, val);
 }

 public static double GetScaleX(DependencyObject obj)
 {
  return (double)obj.GetValue(ScaleXProperty);
 }

Edit: I've tried it with and without the call to InvalidateArrange (which is absolutely necessary in any case) and the result is the same. The event handler doesn't even get called before the Catastrophic error kicks off.

A: 

Does those two DPs have something in common? Little more details about the DPs will help

Jobi Joy
In my simplified test case they are both doubles, representing X and Y scale factors. My panel scales the X and Y position of objects while leaving their size unchanged.
Jim Lynn
A: 

I would try commenting out the InvalidateArrange in the OnPropertyChanged and see what happens.

A: 

I ran into the same issue. See this forum post.

I solved it using a more generic method of animating. See my blog post.

dcstraw
+1  A: 

It's a documented bug with Silverlight 2 Beta 2. You can't animate two custom dependancy properties on the same object.

Arun
A: 

I hope it's not bad form to answer my own question.

Silverlight 2 Release Candidate 0 was released today, I've tested this problem on it, and it appears to have been fixed. Both Custom DPs in my test panel can now be animated properly, so the app is behaving as expected. Which is nice.

Note that this RC is only a developer-based RC so the standard build of Silverlight hasn't been updated. I'd expect it to be fully released in the next month, though.

Jim Lynn