1

我想为改变高度的 RowDefinition 制作一个故事板,我发现对我有帮助。当我想创建类GridLengthAnimation时,唯一的问题是我无法将其设为 AnimationTimeline。这是因为windows phone 8不支持吗?

在这种情况下,是否有另一种方法可以为 RowDefinition 制作故事板?

4

1 回答 1

1

最简单的方法可能是将网格放置在行中,并像这样为它们的高度属性设置动画。

这是xaml:

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid Background="AliceBlue"
          Grid.Row="0"
          Height="100"
          Tap="Grid_Tap"
          CacheMode="BitmapCache" />
    <Grid Background="AntiqueWhite"
          Grid.Row="1"
          Height="100"
          Tap="Grid_Tap"
          CacheMode="BitmapCache" />
    <Grid Background="Aqua"
          Grid.Row="2"
          Height="100"
          Tap="Grid_Tap"
          CacheMode="BitmapCache" />
    <Grid Background="Aquamarine"
          Grid.Row="3"
          Height="100"
          Tap="Grid_Tap"
          CacheMode="BitmapCache" />

</Grid>

和cs:

private void AnimateHeight(Grid grid)
{
    double newHeight = grid.ActualHeight == 100 ? 300 : 100; //select the height we want to animate

    Storyboard story = new Storyboard();
    DoubleAnimation animation = new DoubleAnimation();
    animation.To = newHeight;
    animation.Duration = TimeSpan.FromSeconds(0.5);

    Storyboard.SetTarget(animation, grid);
    Storyboard.SetTargetProperty(animation, new PropertyPath(Grid.HeightProperty));

    story.Children.Add(animation);
    story.Begin();
}

private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    Grid grid = sender as Grid; //select the grid we tapped
    AnimateHeight(grid);
}

请注意,我将 cachemode 放入 bitmapcache 所有网格。这不是必需的,但可以提供更流畅的动画,因为静态网格不会在每一帧中重新绘制。

于 2014-07-04T11:05:08.783 回答