5

I need to animate this property using a Storyboard. Is writing your own animation is a best choice?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99

1 Answers1

9

No, it is quite possible using the standard XAML:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" x:Name="col0"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.Resources>
        <Storyboard x:Key="sbCol0ToAuto">
            <ObjectAnimationUsingKeyFrames 
                BeginTime="0" Duration="0"
                Storyboard.TargetName="col0" Storyboard.TargetProperty="Width">
                <DiscreteObjectKeyFrame KeyTime="0">
                    <DiscreteObjectKeyFrame.Value>
                        <GridLength>*</GridLength>
                     </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
             </ObjectAnimationUsingKeyFrames>
         </Storyboard>
    </Grid.Resources>
...
</Grid>

And even easier back to Auto:

<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static GridLength.Auto}">
Alex Wiese
  • 8,142
  • 6
  • 42
  • 71
Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99
  • 1
    Except this won't actually animate anything as it won't interpolate between objects/structs like this. Also, you can shorthand this as Value="*", you don't need to declare the GridLength struct. If you really want to animate it you'll need your own animation. – Jeff Aug 14 '12 at 20:05