在做WPF开发的时候,有的时候需要在后台cs来控制动画的添加与移除,在前台XAML和后台添加动画与移除动画的代码如下:
前台XAML:
<i:Interaction.Behaviors>
            <ei:TranslateZoomRotateBehavior x:Name="eiPic" ConstrainToParentBounds="True" TranslateFriction="0.1" RotationalFriction="0.1"/>
            <ei:FluidMoveBehavior Duration="0:0:2">
                <ei:FluidMoveBehavior.EaseY>
                    <BackEase EasingMode="EaseOut"/>
                </ei:FluidMoveBehavior.EaseY>
                <ei:FluidMoveBehavior.EaseX>
                    <BackEase EasingMode="EaseOut"/>
                </ei:FluidMoveBehavior.EaseX>
            </ei:FluidMoveBehavior>
        </i:Interaction.Behaviors>
后台cs代码:
 var behaviors =
        System.Windows.Interactivity
        .Interaction.GetBehaviors(RootGrid);
 if (behaviors.Count == 0)
                {
                    var mtb = new TranslateZoomRotateBehavior
                    {
                        ConstrainToParentBounds = true,
                        TranslateFriction = 0.1,
                        RotationalFriction = 0.1
                    };
                    behaviors.Add(mtb);
                }
//清除动画
                    behaviors.Clear();
原文:http://www.cnblogs.com/unknowngood-1990/p/5714774.html