1

I was just wondering if it's possible to animate the height of a grid using purely XAML? I looked at this tutorial: http://windowsclient.net/learn/video.aspx?v=70654

But it seems as though one need to write custom functions for this to work. Can it be done just by XAML purely?

Kenny Bones
  • 5,017
  • 36
  • 111
  • 174
  • You can -- answered correctly in this SO question. http://stackoverflow.com/q/2239299/22539 – foson Nov 20 '11 at 04:48

2 Answers2

3

its not possible out of the box because there's no such class as a GridLengthAnimation (compare with DoubleAnimation). If such a class existed (from you, microsoft or third party) then there would be a pure XAML solution.

Rob Fonseca-Ensor
  • 15,510
  • 44
  • 57
  • But I've seen animations done which target the Grid itself to manipulate it's properties. But what I want is probably to target the specific row and alter it's properties? So I can manipulate a Grid, but not it's columns and rows? – Kenny Bones Jul 27 '09 at 14:24
  • 1
    well you can't target everything in a grid. You can't animate its name, its alignment, the number of columns, the "visibility" (although opacity is available) because each of these properties is of a type that has no corresponding *Animation class. You can animate any properties that are Dependency Properties and are Colors, Doubles, Ints, Boolean etc (see http://msdn.microsoft.com/en-us/library/system.windows.media.animation.aspx for all 2D animations). Grid columns & rows have their lengths specified as GridLength properties, so no, you can't animate them without some extra code. – Rob Fonseca-Ensor Jul 28 '09 at 07:41
0
<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="0" x:Name="Row" />
  </Grid.RowDefinitions>
</Grid>
...
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Row" 
                               Storyboard.TargetProperty="Height" Duration="0:0:0.2">
  <DiscreteObjectKeyFrame Value="{x:Static GridLength.Auto}" KeyTime="0:0:0.2" />
</ObjectAnimationUsingKeyFrames>
huang
  • 919
  • 11
  • 22