How to discrete animate GridLength from “Auto” to “*”?

a 夏天 提交于 2020-01-13 12:08:32

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/2239299/how-to-discrete-animate-gridlength-from-auto-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!