sony
sony

Reputation: 1503

Doubleanimation resets the values?

I have a double animation, where the window gets scaled down and moved to the side. I do this in the Window_Deactivated event. The code is below:

        <Storyboard x:Key="StoryTestScaleDownGrd1">

        <DoubleAnimation Storyboard.TargetName="ScaleUp" Storyboard.TargetProperty="ScaleX" 
                       From="1" To=".20" Duration="0:0:.25" BeginTime="00:00:00" />

        <DoubleAnimation Storyboard.TargetName="ScaleUp" Storyboard.TargetProperty="ScaleY" 
                       From="1" To=".20" Duration="0:0:.25" BeginTime="00:00:00" />            

        <DoubleAnimation Storyboard.TargetName="MoveCenter1" Storyboard.TargetProperty="OffsetX"
                         Duration="0:0:.25" BeginTime="00:00:00.25" />

        <DoubleAnimation Storyboard.TargetName="MoveCenter1" Storyboard.TargetProperty="OffsetY" 
                         Duration="0:0:.25" BeginTime="00:00:00.25"/>

    </Storyboard>

In the Window_Activated event, I have the code below:

        <Storyboard x:Key="StoryTestScaleUpGrd1">

        <DoubleAnimation Storyboard.TargetName="ScaleUp" Storyboard.TargetProperty="ScaleX" 
                       From=".20" To="1" Duration="0:0:.25" BeginTime="00:00:00.75" />

        <DoubleAnimation Storyboard.TargetName="ScaleUp" Storyboard.TargetProperty="ScaleY" 
                         From=".20" To="1" Duration="0:0:.25" BeginTime="00:00:00.75" />

        <DoubleAnimation Storyboard.TargetName="MoveCenter1" Storyboard.TargetProperty="OffsetX" 
                        Duration="0:0:.25" BeginTime="00:00:00.5" />

        <DoubleAnimation Storyboard.TargetName="MoveCenter1" Storyboard.TargetProperty="OffsetY" 
                        Duration="0:0:.25" BeginTime="00:00:00.5" />

    </Storyboard>

My viewport2dvisual3d is below:

        <Viewport2DVisual3D.Transform>
            <Transform3DGroup>

                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D x:Name="Win1Angle" Angle="0" Axis="0, 1, 0" />
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>

                <ScaleTransform3D x:Name="ScaleUp"  />
                <ScaleTransform3D x:Name="ScaleDown"  />

                <TranslateTransform3D x:Name="MoveCenter1" OffsetX="0" OffsetY="0" />

            </Transform3DGroup>
        </Viewport2DVisual3D.Transform>


        <!-- The Geometry, Material, and Visual for the Viewport2DVisual3D -->
        <Viewport2DVisual3D.Geometry>
            <!-- positions of triangle    0          1           2           3      -->

            <MeshGeometry3D Positions="-.78,.58,0  -.78,-.58,0    .78,-.58,0    .78,.58,0"                                
                                    TextureCoordinates="0,0 0,1 1,1 1,0" 
                                    TriangleIndices="0 1 2 0 2 3" />

        </Viewport2DVisual3D.Geometry>

        <Viewport2DVisual3D.Material>
            <DiffuseMaterial  Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
        </Viewport2DVisual3D.Material>

        <Grid x:Name="grdHolder1" VerticalAlignment="Center" HorizontalAlignment="Center" ClipToBounds="False" Opacity="1" />

    </Viewport2DVisual3D>

The code for doing the animation is below:

window deactivated

StoryDeActivatedGrd1 = (Storyboard)this.Resources["StoryTestScaleDownGrd1"];


  (StoryDeActivatedGrd1.Children[2] as DoubleAnimation).From = 0.0;
            (StoryDeActivatedGrd1.Children[2] as DoubleAnimation).To = (double)GV.oCoOrdinate.XValue;
            (StoryDeActivatedGrd1.Children[3] as DoubleAnimation).From = 0.0;
            (StoryDeActivatedGrd1.Children[3] as DoubleAnimation).To = (double)GV.oCoOrdinate.YValue;
            StoryDeActivatedGrd1.Begin();

In the activated event, I have the following code:

 StoryActivatedGrd1 = (Storyboard)this.Resources["StoryTestScaleUpGrd1"];

 (StoryActivatedGrd1.Children[2] as DoubleAnimation).To = 0.0;
                (StoryActivatedGrd1.Children[3] as DoubleAnimation).To = 0.0;
                StoryActivatedGrd1.Begin();

My problem is that, my window is extremely small when the window gets activated. Is there a way we can reset the window size after the first animation?

Actually, I use two grids to hold the usercontrols at runtime, I have the first grid working easily, but when the window flips to the second usercontrol, I have the problem as above...

Upvotes: 2

Views: 1788

Answers (2)

Louis Kottmann
Louis Kottmann

Reputation: 16648

You can use any kind of animation without from/to set to make it reset to default:

<DoubleAnimation Storyboard.TargetName="ScaleUp" 
                 Storyboard.TargetProperty="ScaleX" 
                 Duration="0:0:.25" />

This would reset the ScaleX property.

You can wrap the 4 properties you modify (or a selection) in a Storyboard and fire it when the window is activated.

Upvotes: 2

icebat
icebat

Reputation: 4774

If you want to reset animated property to it`s original state you can set FillBehavior property to Stop on Animations that alter that property.

Upvotes: 5

Related Questions