WinRT动画不显示中间值

时间:2014-11-18 03:51:20

标签: .net xaml animation windows-runtime winrt-xaml

在WinRT中,许多动画根本不显示任何中间值,或者仅在您移动鼠标或其他系统事件时才显示它们,这很奇怪。在动画结束时,值设置正确,但在执行期间(在我的情况下是动画的2秒持续时间),中间值永远不会显示。

2秒后,窗口消失,但是当你按X时,你看不到它在翻转。有时如果你在动画中移动鼠标,你可以看到它,但这通常只发生在XAML图表更多时复杂。

这是XAML:



<Grid Background="#525252">
        <Grid x:Name="AnimatedDialog"
              HorizontalAlignment="Center"
              VerticalAlignment="Center">
            <Grid.Projection>
                <PlaneProjection />
            </Grid.Projection>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Border Grid.RowSpan="2"
                    Grid.ColumnSpan="2"
                    Background="White"
                    BorderBrush="#2E2E2E"
                    BorderThickness="1" />

            <Border Background="#2E2E2E" />
            <TextBlock Grid.Row="0"
                       Grid.Column="0"
                       Margin="10,5"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       FontFamily="Segoe UI"
                       FontSize="20"
                       FontWeight="SemiBold"
                       Text="{Binding Title,
                                      ElementName=Root,
                                      FallbackValue='This is the title'}" />
            <Border Grid.Row="0"
                    Grid.Column="1"
                    Width="40"
                    Height="40"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    Background="#BD0000"
                    BorderThickness="0"
                    Padding="0"
                    PointerReleased="CloseBorder_OnPointerReleased" />
            <TextBlock Grid.Row="0"
                       Grid.Column="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       FontFamily="Segoe UI Symbol"
                       FontSize="22"
                       Foreground="White"
                       IsHitTestVisible="False"
                       Text="❌" />

            <TextBlock Grid.Row="1"
                       Grid.Column="0"
                       Grid.ColumnSpan="2"
                       Width="550"
                       Height="360"
                       Margin="10"
                       FontSize="22"
                       Foreground="Black"
                       IsHitTestVisible="False"
                       Text="Bacon ipsum dolor amet boudin ground round drumstick porchetta prosciutto spare ribs short ribs bresaola leberkas hamburger sirloin shank tri-tip turkey strip steak. Rump boudin shank, ham hock bresaola shankle shoulder. Alcatra landjaeger kevin tail hamburger turducken flank pork. Meatloaf turducken leberkas, pig sausage pancetta ground round. Beef kevin swine tongue ham hock bacon shoulder leberkas kielbasa rump capicola ribeye chicken shankle venison. Biltong ball tip prosciutto, t-bone cow pork ribeye pancetta strip steak jowl ham drumstick landjaeger short ribs andouille. Turducken tail shankle bacon, pork turkey filet mignon ham pig."
                       TextWrapping="WrapWholeWords" />
        </Grid>
    </Grid>
&#13;
&#13;
&#13;

代码背后:

        private void CloseBorder_OnPointerReleased(object sender, PointerRoutedEventArgs e)
        {
            // Spin AnimatedDialog to close.

            var storyboard = new Storyboard();

            var projection = AnimatedDialog.Projection as PlaneProjection;
            projection.CenterOfRotationY = 0.5;

            var flipAnim = new DoubleAnimation();

            Storyboard.SetTarget(flipAnim, projection);
            Storyboard.SetTargetProperty(flipAnim, "RotationX");

            // 2 second flip
            flipAnim.Duration = new Duration(new TimeSpan(0, 0, 2));
            flipAnim.EasingFunction = new QuadraticEase {EasingMode = EasingMode.EaseIn};
            flipAnim.From = 0;
            flipAnim.To = 90;

            storyboard.Children.Add(flipAnim);

            storyboard.Completed += StoryboardOnCompleted;

            storyboard.Begin();
        }

        private void StoryboardOnCompleted(object sender, object o)
        {
            Debug.WriteLine("Completed storyboard.");
        }

2 个答案:

答案 0 :(得分:2)

出于某种原因,当您使用接近零的值但实际上不是零时,它会起作用。

        private void CloseBorder_OnPointerReleased(object sender, PointerRoutedEventArgs e)
        {
            // Spin AnimatedDialog to close.

            var storyboard = new Storyboard();

            var projection = AnimatedDialog.Projection as PlaneProjection;
            projection.CenterOfRotationY = 0.5;
            projection.RotationX = .0000000001;  // <--- this line changed

            var flipAnim = new DoubleAnimation();

            Storyboard.SetTarget(flipAnim, projection);
            Storyboard.SetTargetProperty(flipAnim, "RotationX");

            // 2 second flip
            flipAnim.Duration = new Duration(new TimeSpan(0, 0, 2));
            flipAnim.EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseIn };
            flipAnim.From = projection.RotationX;  // <--- this line changed
            flipAnim.To = 90;

            storyboard.Children.Add(flipAnim);

            storyboard.Completed += StoryboardOnCompleted;

            storyboard.Begin();
        }

        private void StoryboardOnCompleted(object sender, object o)
        {
            Debug.WriteLine("Completed storyboard.");
        }

答案 1 :(得分:0)

添加flipAnim.EnableDependentAnimation = true;并且它会起作用。