2016-02-26 149 views
0

我正在尝试使用动画折叠/展开网格,并在动画时移动所有其他组件。展开/折叠网格

到目前为止我用

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="GridName"> 
    <DiscreteObjectKeyFrame KeyTime="0:0:0.59" Value="0,0,0,0" /> 
    (...more frames) 
</ObjectAnimationUsingKeyFrames > 

但是效果远远可接受(动画不平滑)。如果新控件有这样的选项,我是在徘徊?我也遇到了一些扩展/折叠ListViews - 但它们不适用于包含数据。

编辑:我试着动画的高度属性 - 但没有发生(没有错误和没有可见的结果)。我的代码如下:

<Storyboard x:Name="MainImageSlideOut"> 
     <DoubleAnimation Duration="0:0:1" To="0" 
          Storyboard.TargetProperty="Height" 
          Storyboard.TargetName="Grid" 
          EnableDependentAnimation="True"/> 

</Storyboard> 
<Storyboard x:Name="MainImageSlideIn"> 
     <DoubleAnimation Duration="0:0:1" To="250" 
          Storyboard.TargetProperty="Height" 
          Storyboard.TargetName="Grid" 
          EnableDependentAnimation="True"/> 

</Storyboard> 

.... 

<Grid Background="#171717"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"></RowDefinition> 
     <RowDefinition Height="*"></RowDefinition> 
    </Grid.RowDefinitions> 

    <Grid Grid.Row="1" 
      Height="250" 
      x:Name="Grid" 
      Background="#202020" />    

    <ScrollViewer Grid.Row="2"> 
    ... 
    </ScrollViewer> 

</Grid> 

回答

1

我在我的应用程序中有类似的功能。
我用它是通过使用这里的ScaleTransform方式是一个例子:

<Storyboard x:Key="gridLoading"> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="IAmGroot"> 
     <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
     <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"> 
      <EasingDoubleKeyFrame.EasingFunction> 
       <CubicEase EasingMode="EaseOut"/> 
      </EasingDoubleKeyFrame.EasingFunction> 
     </EasingDoubleKeyFrame> 
    </DoubleAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="IAmGroot"> 
     <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
     <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

这将加载从屏幕中间的网格,展开以适合屏幕大小。
如果您想要对所有元素执行动画,那么这个动画将执行该操作,但是如果您需要不同的行为,则可能需要单独处理Grid中的项目的动画。
HTH

+0

Il看起来很完美 - 但在网格下方,我试图进行动画处理,还有另一个网格应该采用当前网格的位置。不幸的是,它没有。两个网格都位于主网格内,其中第一个为自动定义,第二个为*。 –

+0

为此的一种方法是操纵其中一个网格的高度,然后另一个将自动调整其自身以适合内容,这意味着只有一个动画而不是2个。网格是否在同一行? – XAMlMAX

+0

否 - 它们是不同的行 –