如何在Windows 8 XAML中设置控件高度的动画

Pet*_*ete 14 xaml windows-8 windows-runtime winrt-xaml

我在Windows 8上的Metro风格的C#/ XAML应用程序中执行一个简单的基于故事板的控件高度动画时遇到了麻烦.

以下简单的XAML和代码片段背后的代码在Silverlight 5和Windows Phone 7中运行良好,但在Windows 8中什么都不做(至少对我来说):

<Page.Resources>
    <Storyboard x:Name="expandAnimation">
        <DoubleAnimation Storyboard.TargetName="scaleButton" Storyboard.TargetProperty="Height" From="50" To="200" Duration="0:0:1"/>
    </Storyboard>
</Page.Resources>

<StackPanel Width="200">
    <Button x:Name="scaleButton" Click="scaleButton_Click" Content="Scale"/>
    <Button Content="Another button"/>
    <Button Content="Yet another button"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

C#代码:

private void scaleButton_Click(object sender, RoutedEventArgs e)
{
    expandAnimation.Begin();
}
Run Code Online (Sandbox Code Playgroud)

可以更改相同的代码以动画控件的其他属性,例如Opacity,它按预期工作.

我可以设置ScaleTransform的动画来进行缩放,但它会改变控件的内部渲染,并且不会影响相邻控件的布局,这对我来说是一个问题.

希望我不会错过任何明显的东西,但这不应该只是工作吗?

Sof*_*ide 29

你只需要添加EnableDependentAnimation="True"然后它应该工作正常.