Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate height of control in Windows 8 XAML

I'm having trouble performing a simple storyboard-based animation of a controls height in a Metro-style C#/XAML application on Windows 8.

The following trivial XAML and code behind snippets work fine in Silverlight 5 and Windows Phone 7, yet do nothing in Windows 8 (at least for me):

<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>

C# code:

private void scaleButton_Click(object sender, RoutedEventArgs e)
{
    expandAnimation.Begin();
}

The same code can be altered to animate other properties of the control such as Opacity which works as expected.

I can animate a ScaleTransform to do the scaling, but it alters the internal rendering of the control, and does not affect the layout of neighbouring controls which is a problem for me.

Hopefully I'm not missing anything obvious here, but shouldn't this just work?

like image 720
Pete Avatar asked May 07 '12 09:05

Pete


1 Answers

You just need to add EnableDependentAnimation="True" and then it should work fine.

like image 196
Sofian Hnaide Avatar answered Oct 28 '22 04:10

Sofian Hnaide