diff --git a/MapControl/Avalonia/MapImageLayer.Avalonia.cs b/MapControl/Avalonia/MapImageLayer.Avalonia.cs index 28d54690..5d4f37d6 100644 --- a/MapControl/Avalonia/MapImageLayer.Avalonia.cs +++ b/MapControl/Avalonia/MapImageLayer.Avalonia.cs @@ -8,7 +8,7 @@ namespace MapControl { public partial class MapImageLayer { - public static void FadeOver(Image topImage, Image bottomImage) + private void FadeOver() { var fadeInAnimation = new Animation { @@ -24,8 +24,8 @@ namespace MapControl } }; - _ = fadeInAnimation.RunAsync(topImage).ContinueWith( - _ => bottomImage.Opacity = 0d, + _ = fadeInAnimation.RunAsync(Children[1]).ContinueWith( + _ => Children[0].Opacity = 0d, TaskScheduler.FromCurrentSynchronizationContext()); } } diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index 720474c9..de131363 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -125,10 +125,7 @@ namespace MapControl /// /// Gets the progress of the ImageLoader as a double value between 0 and 1. /// - public double LoadingProgress - { - get => (double)GetValue(LoadingProgressProperty); - } + public double LoadingProgress => (double)GetValue(LoadingProgressProperty); protected override void SetParentMap(MapBase map) { @@ -136,11 +133,7 @@ namespace MapControl { while (Children.Count < 2) { - Children.Add(new Image - { - Opacity = 0d, - Stretch = Stretch.Fill, - }); + Children.Add(new Image { Stretch = Stretch.Fill }); } } else @@ -236,7 +229,6 @@ namespace MapControl if (Children.Count >= 2) { var topImage = (Image)Children[0]; - var bottomImage = (Image)Children[1]; Children.RemoveAt(0); Children.Insert(1, topImage); @@ -244,7 +236,7 @@ namespace MapControl topImage.Source = image; SetBoundingBox(topImage, boundingBox); - FadeOver(topImage, bottomImage); + FadeOver(); } } } diff --git a/MapControl/WPF/MapImageLayer.WPF.cs b/MapControl/WPF/MapImageLayer.WPF.cs index ad8f1aba..cb401c84 100644 --- a/MapControl/WPF/MapImageLayer.WPF.cs +++ b/MapControl/WPF/MapImageLayer.WPF.cs @@ -3,14 +3,14 @@ // Licensed under the Microsoft Public License (Ms-PL) using System; -using System.Windows.Controls; +using System.Windows; using System.Windows.Media.Animation; namespace MapControl { public partial class MapImageLayer { - public static void FadeOver(Image topImage, Image bottomImage) + private void FadeOver() { var fadeInAnimation = new DoubleAnimation { @@ -25,8 +25,16 @@ namespace MapControl Duration = TimeSpan.Zero }; - topImage.BeginAnimation(OpacityProperty, fadeInAnimation); - bottomImage.BeginAnimation(OpacityProperty, fadeOutAnimation); + Storyboard.SetTarget(fadeInAnimation, Children[1]); + Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(OpacityProperty)); + + Storyboard.SetTarget(fadeOutAnimation, Children[0]); + Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(OpacityProperty)); + + var storyboard = new Storyboard(); + storyboard.Children.Add(fadeInAnimation); + storyboard.Children.Add(fadeOutAnimation); + storyboard.Begin(); } } } diff --git a/MapControl/WinUI/MapImageLayer.WinUI.cs b/MapControl/WinUI/MapImageLayer.WinUI.cs index 12be719d..6389c7ca 100644 --- a/MapControl/WinUI/MapImageLayer.WinUI.cs +++ b/MapControl/WinUI/MapImageLayer.WinUI.cs @@ -4,10 +4,8 @@ using System; #if UWP -using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; #else -using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; #endif @@ -15,7 +13,7 @@ namespace MapControl { public partial class MapImageLayer { - public static void FadeOver(Image topImage, Image bottomImage) + private void FadeOver() { var fadeInAnimation = new DoubleAnimation { @@ -30,11 +28,11 @@ namespace MapControl Duration = TimeSpan.Zero }; + Storyboard.SetTarget(fadeInAnimation, Children[1]); Storyboard.SetTargetProperty(fadeInAnimation, nameof(Opacity)); - Storyboard.SetTarget(fadeInAnimation, topImage); + Storyboard.SetTarget(fadeOutAnimation, Children[0]); Storyboard.SetTargetProperty(fadeOutAnimation, nameof(Opacity)); - Storyboard.SetTarget(fadeOutAnimation, bottomImage); var storyboard = new Storyboard(); storyboard.Children.Add(fadeInAnimation); diff --git a/MapControl/WinUI/Tile.WinUI.cs b/MapControl/WinUI/Tile.WinUI.cs index 13a63d9c..f1291a00 100644 --- a/MapControl/WinUI/Tile.WinUI.cs +++ b/MapControl/WinUI/Tile.WinUI.cs @@ -25,8 +25,8 @@ namespace MapControl FillBehavior = FillBehavior.Stop }; - Storyboard.SetTargetProperty(fadeInAnimation, nameof(UIElement.Opacity)); Storyboard.SetTarget(fadeInAnimation, Image); + Storyboard.SetTargetProperty(fadeInAnimation, nameof(UIElement.Opacity)); var storyboard = new Storyboard(); storyboard.Children.Add(fadeInAnimation);