mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Reworked animations
This commit is contained in:
parent
12b33c5376
commit
8708c7ffe6
9 changed files with 159 additions and 85 deletions
|
|
@ -1,35 +0,0 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
#else
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
internal static class Animatable
|
||||
{
|
||||
public static void BeginAnimation(this DependencyObject obj, string property, Timeline animation)
|
||||
{
|
||||
Storyboard.SetTargetProperty(animation, property);
|
||||
Storyboard.SetTarget(animation, obj);
|
||||
|
||||
var storyboard = new Storyboard();
|
||||
storyboard.Children.Add(animation);
|
||||
storyboard.Begin();
|
||||
}
|
||||
|
||||
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, Timeline animation)
|
||||
{
|
||||
if (animation != null && property == UIElement.OpacityProperty)
|
||||
{
|
||||
BeginAnimation(obj, nameof(UIElement.Opacity), animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ namespace MapControl
|
|||
|
||||
centerAnimation.Completed += CenterAnimationCompleted;
|
||||
|
||||
this.BeginAnimation(nameof(AnimatedCenter), centerAnimation);
|
||||
BeginAnimation(nameof(AnimatedCenter), centerAnimation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -270,7 +270,7 @@ namespace MapControl
|
|||
|
||||
zoomLevelAnimation.Completed += ZoomLevelAnimationCompleted;
|
||||
|
||||
this.BeginAnimation(nameof(ZoomLevel), zoomLevelAnimation);
|
||||
BeginAnimation(nameof(ZoomLevel), zoomLevelAnimation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -346,7 +346,7 @@ namespace MapControl
|
|||
|
||||
headingAnimation.Completed += HeadingAnimationCompleted;
|
||||
|
||||
this.BeginAnimation(nameof(Heading), headingAnimation);
|
||||
BeginAnimation(nameof(Heading), headingAnimation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -362,5 +362,15 @@ namespace MapControl
|
|||
headingAnimation = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginAnimation(string property, Timeline animation)
|
||||
{
|
||||
Storyboard.SetTarget(animation, this);
|
||||
Storyboard.SetTargetProperty(animation, property);
|
||||
|
||||
var storyboard = new Storyboard();
|
||||
storyboard.Children.Add(animation);
|
||||
storyboard.Begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
47
MapControl/WinUI/OpacityHelper.WinUI.cs
Normal file
47
MapControl/WinUI/OpacityHelper.WinUI.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
#else
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public static class OpacityHelper
|
||||
{
|
||||
public static void BeginOpacityAnimation(DependencyObject obj, DoubleAnimation animation)
|
||||
{
|
||||
Storyboard.SetTargetProperty(animation, nameof(UIElement.Opacity));
|
||||
Storyboard.SetTarget(animation, obj);
|
||||
|
||||
var storyboard = new Storyboard();
|
||||
storyboard.Children.Add(animation);
|
||||
storyboard.Begin();
|
||||
}
|
||||
|
||||
public static async Task SwapOpacities(UIElement topElement, UIElement bottomElement)
|
||||
{
|
||||
BeginOpacityAnimation(topElement, new DoubleAnimation
|
||||
{
|
||||
To = 1d,
|
||||
Duration = MapBase.ImageFadeDuration
|
||||
});
|
||||
|
||||
BeginOpacityAnimation(bottomElement, new DoubleAnimation
|
||||
{
|
||||
To = 0d,
|
||||
BeginTime = MapBase.ImageFadeDuration,
|
||||
Duration = TimeSpan.Zero
|
||||
});
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ namespace MapControl
|
|||
{
|
||||
private void BeginOpacityAnimation()
|
||||
{
|
||||
Image.BeginAnimation(UIElement.OpacityProperty,
|
||||
OpacityHelper.BeginOpacityAnimation(Image,
|
||||
new DoubleAnimation
|
||||
{
|
||||
From = 0d,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue