我有一个双动画,窗口缩小并移到一边。我在Window_Deactivated事件中执行此操作。代码如下:
<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>
在Window_Activated事件中,我有以下代码:
<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>
我的viewport2dvisual3d如下:
<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>
执行动画的代码如下:
停用窗口
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();
在激活的事件中,我有以下代码:
StoryActivatedGrd1 = (Storyboard)this.Resources["StoryTestScaleUpGrd1"];
(StoryActivatedGrd1.Children[2] as DoubleAnimation).To = 0.0;
(StoryActivatedGrd1.Children[3] as DoubleAnimation).To = 0.0;
StoryActivatedGrd1.Begin();
我的问题是,当窗口被激活时,我的窗口非常小。有没有办法在第一个动画后重置窗口大小?
实际上,我使用两个网格来保存运行时的用户控件,我让第一个网格很容易工作,但是当窗口翻转到第二个用户控件时,我遇到了上面的问题......
答案 0 :(得分:4)
如果要将动画属性重置为原始状态,可以将FillBehavior属性设置为“停止动画”以更改该属性。
答案 1 :(得分:0)
您可以使用任何类型的动画,而无需设置/将其重置为默认值:
<DoubleAnimation Storyboard.TargetName="ScaleUp"
Storyboard.TargetProperty="ScaleX"
Duration="0:0:.25" />
这将重置ScaleX属性。
您可以将您修改的4个属性(或选择)包装在故事板中,并在激活窗口时将其激活。