Examine the Start Project
A fair amount has been included with this starter project so the focus can remain
on the LayoutStates.
- A Sample Data source had been created where the Items have a string and image property
- A ListBox has been added and bound to the SampleData
- A custom ItemPanelTemplate has been created using a WrapPanel
- A custom ItemTemplate has been created to display the properties of the Items
- Add and Remove buttons have been created with event handlers that add and remove
randomly generated items
If you run the project, you will notice that once items are added or removed they
instantly appear or disappear.
Bring In the ListBoxItem
Now let’s use the new states to animate the items on and off the screen.
- Right-click the ListBox and select the Edit Additional Templates -> Edit Generated
Item Container (ItemContainerStyle) -> Edit a Copy… option.
- On the Create Style Resource dialog, hit OK.
- In the States panel, change the Default transition from zero seconds to half a second
(0.5 s).
- Select the BeforeLoaded state.
- Select the base Grid of the template.
- Change the Opacity to 0.
- Change the Projection Y Angle to -90.
As the names imply, the BeforeLoaded state occurs right before the ListBoxItem is
added to the ListBox and the AfterLoaded state happens after the ListBoxItem is
added. This makes for a good pair of states to animate between for transitions while
maintaining a clean base state.
Send the ListBoxItem Away
For the BeforeUnloaded state, we will create a custom transition.
- Select the BeforeUnloaded state.
- Click the Add Transition button (
) and select the “* -> BeforeUnloaded” option.
- Click the FX button on the new transition and select the Pixelate option.
- Select the base Grid of the template.
- Set the Opacity to 0.
- Run the project and watch the items fade and flip into view when added and then
watch as they pixelate away when removed.