VSM: Is it possible to animate the size of the custom control?

Apr 24, 2009 at 1:27 PM
Let's say I have a custom control which Height property I want to animate on mouseover. The root element in my controltemplate is a border named 'Bd', in which I have defined the vsm stuff.
I know I can animate the background like this: 
<ColorAnimation Storyboard.TargetName="Bd" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"...

I could use something similar for the height property of the border, but that would animate only the height of the border, not the height of the whole control!
I thought I could leave out StoryBoard.TargetName, but vsm uses a combination of name and property as the key for a flattened list of animations. For comparing these keys the GetHashCode() override uses the same targetname to generate a hashcode. Since the targetname is null when I leave out StoryBoard.TargetName, I get a NullReferenceException :-(

Does anyone know how to animate properties of the control itself, instead of properties of named elements inside the controltemplate???

Thanks,
Marcel
Coordinator
Apr 24, 2009 at 2:06 PM
The TargetName issue that you describe above is a known issue that is logged in our internal bug database.  As for animating properties on the Control itself you will need access at a higher level than the control template.  In the dev10 release we have added this functionality through a new API where you can do VSM on any FrameworkElement (and therefore outside of the control template).  Currently, a workaround is to put your custom control in a UserControl and set the VisualStateGroups on the UserControl.
Apr 24, 2009 at 3:01 PM
Edited Apr 24, 2009 at 3:01 PM
Thanks for your reply. I think your workaround though is not going to work in my case because my custom control is a custom ListBoxItem, to be used in a custom ListBox. In that scenario only the itemcontainer knows it's own size. On a higher level we actually don't want to know... 

Can I use the current visualstate as a condition in a (Data)Trigger? Do you know if that is possible? If so, maybe I could fire my own separate animation from the trigger...
Coordinator
Apr 24, 2009 at 4:17 PM
Hm...I see what you mean.  Currently you cannot use the visualstate as any kind of trigger.  You can listen to the same things that the visualstate listens to and fire an animation with a trigger.  That's probably not what you want to hear though.

I myself went through a similar issue where I wanted all the listboxitems to fly in and out when loaded/unloaded.  I hacked the visualstates to animate padding on the root Border and opacity.  Maybe you can resort to something along those lines?  As far as animating the control itself with what is currently available, there isn't any straightforward way to do it with vsm.