Welcome to MSDN Blogs Sign in | Join | Help

Ed's Blog

Ed Maia's blog covering Silverlight Animation and Media features.
Animating Custom Attached Properties in SL2

One feature in SL2 that was added between Beta 2 and RTW is a new constructor to the PropertyPath class that can be used from code. You can now do the following from code:

Storyboard.SetTargetProperty(myAnimation, new PropertyPath(MyCustomClass.MyCustomDP));

This is especially important if you are trying to target an animation at a custom attached property.  For example:

<DoubleAnimation Storyboard.TargetProperty="(custom:MyCustomClass.MyCustomAttachedDP)" .../>

Specifying these types of property path from a string representation presents a number of complications on the SL, and is not currently supported.  This piece of XAML currently raises an InvalidOperationException with message "Cannot resolve TargetProperty (custom:MyCustomClass.MyCustomAttachedDP)".

Please note that this only applies to custom attached properties - attached properties of built-in objects (e.g., Canvas.Top) as well as custom non-attached properties should work just fine.  As reference, an overview of the PropertyPath syntax can be found here.

Hopefully this will unblock you if you run into this limitation!
Ed

Posted: Thursday, October 16, 2008 12:31 AM by edmaia

Comments

Jeanpylone said:

I finally found the answer I was looking for in this post!!! Thanks to you, even if it doesn't really go in my way, as I still can't do what i'd like to :S

My idea was to use a custom attached property (like here) and animate it in a template (generic.xaml for a custom control with visual states)... So if you have a solution to modify templates' visual states to do it programmatically, you're welcome :)

# March 4, 2009 9:18 AM

Bryant Likes's Blog said:

In my last post I blogged about using Attached Properties to get around the limitation that only Dependency

# March 23, 2009 6:28 PM
Anonymous comments are disabled
Page view tracker