tags:

views:

69

answers:

1

Hi,

In visual studio I get "XAML parsing error" when a story board is run. The application launches but when I mouseover a button which has been templated, the error is shown.

My buttons template (using visual states etc) has a circle that scales which is passed in via a custom attached property.

The code that raises the error at runtime is the value property below:

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
    Storyboard.TargetName="Document"
    Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
  <EasingDoubleKeyFrame KeyTime="00:00:00.7000000"
     Value="{Binding Path=(local:MyAttachedProperties.Scaling), RelativeSource={RelativeSource TemplatedParent}}" />
</DoubleAnimationUsingKeyFrames>;

The code for the attached property is:

public class MyAttachedProperties
{
  public static readonly DependencyProperty ScalingProperty =
    DependencyProperty.RegisterAttached("Scaling",
      typeof(double), typeof(MyAttachedProperties), null);

  // Scaling
  public static double GetScaling(DependencyObject obj) 
  { 
    return (double)obj.GetValue(ScalingProperty); 
  }
  public static void SetScaling(DependencyObject obj, double value) 
  { 
    obj.SetValue(ScalingProperty, value); 
  }
}

and for my button I have:

 <Button Height="76"
         Content="Gallery"
         Style="{StaticResource MyRotatingButtonStyle}" 
         Padding="10"
         local:MyAttachedProperties.Scaling="2" />
+1  A: 

In Silverlight you can't bind on an Animation object they don't derive from FrameworkElement which is required in Silverlight 3 for binding to work.

To achieve your goal you will need to write some code to find the EasingDoubleKeyFrame and adjust the value directly.

AnthonyWJones
Hi Anthony, any idea how to do this? EasingDoubleKeyFrame is in a style so assigning a x:Name to it does not expose it in the code behind file.
JD
This link http://blogs.msdn.com/edmaia/archive/2008/10/16/animating-custom-attached-properties-in-sl2.aspx and http://bryantlikes.com/AnimationHackUsingAttachedPropertiesInSilverlight.aspx get you started. Thanks for all the help. Until the other day, I did not even know what a custom attached property was.
JD