Xaml 使用故事板设置大小更改动画

Xaml 使用故事板设置大小更改动画,xaml,uwp,Xaml,Uwp,我想通过使用故事板更改ScrollViewer的大小,但它不是动画,只是在延迟后立即更改ScrollViewer的大小 以下是我迄今为止尝试的变体: <Storyboard x:Name="ShowMenuStoryboard"> <DoubleAnimation x:Name="changeHeight" Duration="0:0:2"

我想通过使用故事板更改ScrollViewer的大小,但它不是动画,只是在延迟后立即更改ScrollViewer的大小

以下是我迄今为止尝试的变体:

<Storyboard x:Name="ShowMenuStoryboard">
            <DoubleAnimation x:Name="changeHeight" 
                             Duration="0:0:2" 
                             EnableDependentAnimation="True" 
                             Storyboard.TargetName="ScrollViewer" 
                             Storyboard.TargetProperty="Height" 
                             To="500" />
</Storyboard>

<Storyboard x:Name="ShowMenu">
        <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(ScrollViewer.Width)" Storyboard.TargetName="ScrollViewer">
            <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="900"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(ScrollViewer.Height)" Storyboard.TargetName="ScrollViewer">
            <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="640"/>
        </DoubleAnimationUsingKeyFrames>

</Storyboard>

<Storyboard x:Name="ShowSomeThing">
            <DoubleAnimation Duration="0:0:0.5" To="640" Storyboard.TargetProperty="(UIElement.Height)" Storyboard.TargetName="ScrollViewer" d:IsOptimized="True"/>
            <DoubleAnimation Duration="0:0:0.5" To="900" Storyboard.TargetProperty="(UIElement.Width)" Storyboard.TargetName="ScrollViewer" d:IsOptimized="True"/>

</Storyboard>

<Storyboard x:Name="MaybeNow">
            <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(UIElement.Width)" Storyboard.TargetName="ScrollViewer" d:IsOptimized="True">
                <EasingDoubleKeyFrame KeyTime="0:0:1.0" Value="900"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" Storyboard.TargetProperty="(UIElement.Height)" Storyboard.TargetName="ScrollViewer" d:IsOptimized="True">
                <EasingDoubleKeyFrame KeyTime="0:0:1.0" Value="640"/>
            </DoubleAnimationUsingKeyFrames>

</Storyboard>


我做错了什么?

因此,在没有看到完整实现的情况下,我将假设这很可能是因为,虽然确实声明了
To
值,但您仍然需要某种形式的
From
值,或者它无法为动画创建介于两者之间的关键帧

下面是一个简单的例子。请注意
ScrollViewer
本身上设置的高度/宽度。这些作为继承自值的
。如果需要,您可以直接将其包含在故事板中或通过其他方法

视觉输出(以起伏的gif格式)

XAML-PoC

<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.Resources>
            <Storyboard x:Name="CW_AnimSCSizeSample">
                <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True"
                                           Storyboard.TargetProperty="(FrameworkElement.Width)" 
                                           Storyboard.TargetName="scrollViewer">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="500"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames EnableDependentAnimation="True" 
                                           Storyboard.TargetProperty="(FrameworkElement.Height)" 
                                           Storyboard.TargetName="scrollViewer">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="700"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
        </Grid.Resources>

        <Button Content="Animate SV Size 1 time"
                Click="play_CW_AnimSCSizeSample"/>

        <ScrollViewer x:Name="scrollViewer" Grid.Row="1"
                      Height="200" Width="300" 
                      Background="LightBlue" 
                      BorderBrush="Blue" BorderThickness="3"/>


    </Grid>
private void play_CW_AnimSCSizeSample(object sender, RoutedEventArgs e)
        {
            CW_AnimSCSizeSample.Begin();
        }

希望这有帮助,干杯

嗨,就是这样!非常感谢。“这些作为从值继承而来。如果需要,您可以直接将其包含在故事板中或通过其他方法。”帮助了我,因为我使用了{Binding ActualWidth,ElementName=Page},而这些值不会自动提供“From”值。看起来好像任何绑定都没有提供信息,所以我必须在开始()故事板之前手动执行此操作..Freue mich zu helfen:)