Exemple #1
0
        private void Flip()
        {
            if (containerGrid.Children != null && containerGrid.Children.Count > 0)
            {
                var image  = containerGrid.Children[rnd.Next(0, containerGrid.Children.Count)] as Image;
                var uri    = ImageSourceMap.Uris[rnd.Next(0, ImageSourceMap.Count)];
                var source = ImageSourceMap[uri];

                FadeOutStoryboard.Stop();
                FadeInStoryboard.Stop();
                Storyboard.SetTarget(FadeOutAnimation, image);
                Storyboard.SetTarget(FadeInAnimation, image);

                Task.Run(() =>
                {
                    SyncContext.Post((o) => FadeOutStoryboard.Begin(), null);
                    Task.Delay(1_500).GetAwaiter().GetResult();
                    SyncContext.Post((o) =>
                    {
                        ImageSourceMap.MinusOneReference(image.Source);
                        image.Source = source;
                        FadeInStoryboard.Begin();
                    }, null);
                });
            }
        }
        private async void AnimateButton_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            AnimateButton.IsEnabled = false;  // Disable the button while the animation is in progress


            ElementTranslationStoryboard.Children[0].SetValue(DoubleAnimation.FromProperty, isHidden ? -200 : 0);
            ElementTranslationStoryboard.Children[0].SetValue(DoubleAnimation.ToProperty, isHidden ? 0 : -200);
            ElementTranslationStoryboard.Begin();

            if (isHidden)
            {
                FadeInStoryboard.Begin();
            }
            else
            {
                FadeOutStoryboard.Begin();
            }


            await Task.Delay(1000);

            AnimateButton.IsEnabled = true; // Re-enable the button when the animation is complete


            AnimateButton.Content = (string)AnimateButton.Content == "Fly In" ? "Fly Out" : "Fly In";
            isHidden = !isHidden;
        }
 private void FadeOutAnimationButton_Click(object sender, RoutedEventArgs e)
 {
     FadeOutStoryboard.Begin();
 }