2

我有一个包含两个元素的网格,一个搜索表单和一个自定义 UC 来显示项目。当我的页面加载时,查看器控件被隐藏。当单击搜索表单上的按钮时,我会使用情节提要对其进行动画处理。我被困在To=...动画的一部分。我想将它动画到父容器的高度并让它从底部向上滑动。这可能吗?

作为参考,这是我的树结构:

页面资源:

<Storyboard x:Name="animateViewSlide" Storyboard.TargetName="SearchForm" >
        <DoubleAnimation  Storyboard.TargetProperty="Height" To="???" Duration="100"/>
</Storyboard>

控制体:

<Grid x:Name="LayoutRoot">
    <Grid x:Name="SearchForm" Margin="6,6,6,70">
    <uc:AwesomeViewer x:Name="awesomeView" Awesomeness="{Binding SelectedAwesomeThing}" Visibility="Collapsed"/>
</Grid>
4

1 回答 1

1

更新

我确实想出了一个更好的方法,而不是使用 Margin 来单步执行动画,只需用TranslateTransform类似的方式为 Y 轴设置动画;

<Grid x:Name="ItemToMove" 
            Visibility="{Binding Condition, Converter={StaticResource boolVisConv}}" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="30,0,0,-32" Opacity="0">
                <Grid.RenderTransform>
                    <TranslateTransform x:Name="notified" Y="40" />
                </Grid.RenderTransform>
                    <Grid.Triggers>
                    <EventTrigger RoutedEvent="Grid.Loaded">
                        <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="notified" Storyboard.TargetProperty="Y">
                                        <SplineDoubleKeyFrame KeyTime="0:0:1.25" Value="0" />
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ItemToMove" Storyboard.TargetProperty="Opacity">
                                        <SplineDoubleKeyFrame KeyTime="0:0:1.55" Value="1" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Grid.Triggers>

结束更新

Height您的麻烦将源于尝试为自动计算的值设置动画(只有....那么你的“到”值是 800 像素,但我想这不是你要找的。

现在,您通常希望您可以将渲染的大小输入到您的“To”值中,比如通过To="{Binding ActualHeight, ElementName=LayoutRootOROTHERParentContainer}"对吗?然而,不,那也行不通……

因此,虽然其他人可能有更好的方法,但我发现的唯一方法是让自动计算的尺寸独自去做他们的事情,而是为对象的步进设置动画,Margin通过它与转换通过ObjectAnimationUsingKeyFrames配对时实际上看起来相当很好,除了它会为该过程添加一堆额外的 XAML。因此,作为一个概念,您可能会尝试更多类似的东西(但是,如果您遇到更好的解决方案,我肯定也想知道它。作为谋生的设计师,我经常遇到这种情况。)OpacityDoubleAnimationUsingKeyFrames

概念示例;

(故事板)

<Storyboard x:Name="Kaboom">
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="border">
        <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,750,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.2">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,600,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.3">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,550,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.4">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,500,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.5">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,450,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.6">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,400,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.7">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,350,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.8">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,300,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.9">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,250,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:1">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,200,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:1.1">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,150,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:1.2">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,100,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:1.3">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0,50,0,0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:1.4">
            <DiscreteObjectKeyFrame.Value>
                <Thickness>0</Thickness>
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border">
        <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0.01"/>
        <EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="1"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

该概念的一个快速的即席示例;

<Grid Height="800" Width="480" x:Name="ParentContainer">
            <!-- Your SearchForm thingy with its funky margins already set like your example -->
            <Rectangle Margin="6,6,6,70" Fill="Green" />
            <Button Height="100" Width="100" Content="Click Me!" HorizontalAlignment="Left" VerticalAlignment="Top">
                 <!-- Quick button to show it in action -->
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ei:ControlStoryboardAction Storyboard="{StaticResource Kaboom}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
            </Button>
            <!-- Your Awesomeness -->
            <Border x:Name="border" Width="300" Background="Blue" HorizontalAlignment="Right" Margin="0,800,0,0" Opacity="0">
                <TextBlock x:Name="textBlock" Text="OH&#10;&#10;SNAP!!!&#10;&#10;Say&#10;&#10;WHAAA??" 
                            TextAlignment="Center" VerticalAlignment="Center"
                            FontSize="40" FontWeight="Bold" Foreground="White"/>
            </Border>
        </Grid>

无论如何,可能不完全是你所希望的,但它是一个有效的替代方案,尤其是稍微调整一下,除非像我说的那样,你想硬编码你的对象大小,这样你就有了可行的东西来将你的“To”值设置为......对于仅限于标准 800x480 纵向模式的手机,只有您可能非常想要。但是,如果您没有该选项,我已经使用这种方法完成了一些非常漂亮的设计。

希望这会有所帮助,祝你好运!

于 2013-03-08T22:25:49.220 回答