c# - Slide-down animation for ItemsControl -
overview
in wpf/xaml, best way implement slide-down animation when inserting item itemscontrol
?
background
at first glance, seems can use fluidmovebehavior
blend expression interactions namespace. add itemspaneltemplate
itemscontrol
:
<itemspaneltemplate x:key="easein"> <stackpanel isitemshost="true"> <i:interaction.behaviors> <ei:fluidmovebehavior initialtag="datacontext" duration="0:0:0.25" appliesto="children"/> </i:interaction.behaviors> </stackpanel> </itemspaneltemplate>
this nicely slides other items in list down when new item added, doesn't animate newly added item. can add loaded
animation in itemscontrol
itemtemplate
translate item offscreen offset 0:
<datatemplate x:key="datatemplate1"> <grid background="white"> <grid.triggers> <eventtrigger routedevent="loaded"> <beginstoryboard> <storyboard> <doubleanimation storyboard.targetname="animatedtranslatetransform" storyboard.targetproperty="y" from="-10" to="0" duration="0:0:0.25"> </doubleanimation> </storyboard> </beginstoryboard> </eventtrigger> </grid.triggers> <grid.rendertransform> <transformgroup> <translatetransform x:name="animatedtranslatetransform"/> </transformgroup> </grid.rendertransform> <border borderbrush="#ff424242" borderthickness="1"> <stackpanel> <label content="{binding .}"/> </stackpanel> </border> </grid> </datatemplate>
the problem height of items going vary. if set y offset large number, moves @ different rate other items moving down, since has cover greater distance in same amount of time. nice able couple animation new item other items being driven fluidmovebehavior
.
an alternative animation approach animate height of new item 0 auto, has undesired effect of revealing item top down instead of bottom up. give impression of new item in place instead of sliding down top.
questions
how can animate translate transform exact height of item?
i don't mind doing in code behind, since inside of
datatemplate
inside ofitemscontrol
, don't know how retrieve item height programmatically. goal move in @ same rate other items move down.is there easier way animate inserted item in way follows rest of items?
there silverlight/blend articles (here , here) suggest using
visualstatesmanager
, layout states. can changeitemscontrol
listbox
able states initemcontainerstyle
, don't see default layout states in wpf in silverlight.- finally, there way combine 1 animation? nice have animate new item, , have other items react animation @ same rate.
Comments
Post a Comment