A bit more(er) than meets the eye [Easily animate and update LayoutTransformer with AnimationMediator!]

**

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of dlaa.me.

See you there!

Comments

  • Anonymous
    April 10, 2009
    PingBack from http://blogs.msdn.com/delay/archive/2009/04/09/a-bit-more-than-meets-the-eye-easily-animate-layouttransformer-with-animationmediator.aspx

  • Anonymous
    August 11, 2010
    I am experiencing some odd behaviour in SL4 that might warrant some further investigation by someone who better understands dependency properties and the ValueChangedEvent notification chain. When trying to animate multiple transform properties together (ie. Scale.X and Rotate.Angle) the fiollowing XAML works <Storyboard x:Name="myStoryboard1">                                <DoubleAnimation Storyboard.TargetName="scaleTransform1ScaleXMediator"                                             Storyboard.TargetProperty="AnimationValue"                                             From="2.0" To="1.0" Duration="0:0:2" />                                <DoubleAnimation Storyboard.TargetName="scaleTransform1"                                             Storyboard.TargetProperty="ScaleY"                                             From=".1" To="1.0" Duration="0:0:2" />                                <DoubleAnimation Storyboard.TargetName="skewTransform1"                                             Storyboard.TargetProperty="AngleX"                                             From="45" To="0" Duration="0:0:2" />                                <DoubleAnimation Storyboard.TargetName="rotateTransform1"                                             Storyboard.TargetProperty="Angle"                                             From="45" To="0" Duration="0:0:2" />                            </Storyboard> <layout:LayoutTransformer x:Name="txButton1">                            <layout:LayoutTransformer.LayoutTransform>                                <TransformGroup>                                    <ScaleTransform x:Name="scaleTransform1" ScaleX="2" ScaleY=".1"/>                                    <SkewTransform x:Name="skewTransform1" AngleX="45"/>                                    <RotateTransform x:Name="rotateTransform1" Angle="45"/>                                </TransformGroup>                            </layout:LayoutTransformer.LayoutTransform>                            <Button x:Name="TestButton1" Width="120" Height="30" Content="ButtonNameHere" ></Button>                        </layout:LayoutTransformer> <animLT:AnimationMediator x:Name="scaleTransform1ScaleXMediator"                                                 LayoutTransformer="{Binding ElementName=txButton1}"                                                 AnimationValue="{Binding ScaleX, ElementName=scaleTransform1, Mode=TwoWay}"/> Notice I didn't have to create an AnimationMediator for each transform element property (Just the first one) then bind to the others as you might normally think to ... maybe this has something to do with how Mode=TwoWay sets up the event notification pipeline ... but I don't know enough to explore it any further. if I did create  AnimationMediator 's for each tranform property ... it worked nicely too. if this is by-design i apologize I just felt like it was odd behavior based on your documentation ... I expected to have a discrete  AnimationMediator for each property. Robbie Symborski robbie.symborski@live.com

  • Anonymous
    August 11, 2010
    Robbie, The key thing that AnimationMediator does is call LayoutTransformer.ApplyLayoutTransform after each update to the relevant Transforms in order to work around a Silverlight limitation where those changes aren't automatically bubbled up to LayoutTransformer. But ApplyLayoutTransform only needs to be called once per "tick" (i.e., when Silverlight updates all its animations to the next "step"). Because updates all happen together and the specifics of your scenario are such that you're changing a bunch of properties that affect the same LayoutTransformer, you can get away with only one AnimationMediator - when it calls ApplyLayoutTransform, LayoutTransformer looks around, sees the whole batch of updates together, and reacts accordingly. The fact that this optimization works for you is kind of a fortunate consequence of how things are implemented, I'd say. :)

  • Anonymous
    December 22, 2011
    > /// Works around an issue with the Silverlight platform where changes to > /// properties of child Transforms assigned to a Transform property do not > /// trigger the top-level property changed handler (as on WPF). Anyone has any overview if that has been fixed in Silverlight 5? Or do I still need the AnimationMediator?

  • Anonymous
    December 22, 2011
    herzmeister, I'm not in a position to look into this right now, but it should be pretty easy to try in practice by commenting-out the AnimationMediator and seeing if the scenario still works. If anyone happens to investigate sometime soon, I'd be curious to hear the outcome!

  • Anonymous
    July 13, 2012
    Updated my code base to Silverlight 5, found that the AnimationMediator is still required.