Как дискретно анимировать GridLength от «Авто» до «*»?
-
19-09-2019 - |
Вопрос
Мне нужно анимировать это свойство, используя Storyboard
.Является ли написание собственной анимации лучшим выбором?
Решение
Нет, вполне возможно, используя стандартный 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>
А еще проще вернуться в режим Авто:
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static GridLength.Auto}">
Не связан с StackOverflow