I have an ItemsControl with Items being added through databinding to an observable collection. Each item has a data template that defines its look.
I am trying to figure out if it is possible to apply/trigger animations to/on each of the Items in the ItemsControl when the VisualStateManager puts the ItemsControl in a particular state.
Below is a picture – when the items control goes into the closed state – I want the items in the items control to shrink as well as hide the text and have a number become visible. Is this possible using VSM or do I need to attach animations to each item when they are created and then manually kick them off when I want them to change visual state.
This is possible using a ObjectAnimationUsingKeyFrames, however it’s stupidly hard to do, will cause you to rip your hair out, crash your visual studio regularly and gives you very little over doing it the simple way.
The simple way:
Then the xaml to use:
With the following cs in the page:
Now, if you really need to make the control completely extensible by other developers, you’ll need to use visualstatemenager, but it’s a real bitch. If you don’t know how to set up visual state manager and states through generic.xaml, here’s a how-to guide:
http://scorbs.com/2008/06/11/parts-states-model-with-visualstatemanager-part-1-of/
Here’s a working example but it’s not perfect as I can’t seem to set the content of the ContentPresenter directly.
In your generic.xaml (include xmlns:vsm=’clr-namespace:System.Windows;assembly=System.Windows’):
And how to use in your page:
with the following in your page: