XAML-Map-Control/MapControl/UWP/Extensions.UWP.cs

55 lines
1.9 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
namespace MapControl
{
2014-10-30 16:27:36 +01:00
internal static class Extensions
{
public static Point Transform(this GeneralTransform transform, Point point)
{
return transform.TransformPoint(point);
}
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, DoubleAnimation animation)
{
animation.EnableDependentAnimation = true;
BeginAnimation(obj, property, (Timeline)animation);
}
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, PointAnimation animation)
{
animation.EnableDependentAnimation = true;
BeginAnimation(obj, property, (Timeline)animation);
}
private static Dictionary<DependencyProperty, string> properties = new Dictionary<DependencyProperty, string>()
{
{ UIElement.OpacityProperty, "Opacity" },
{ MapBase.ZoomLevelProperty, "ZoomLevel" },
{ MapBase.HeadingProperty, "Heading" },
{ MapBase.CenterPointProperty, "CenterPoint" }
};
private static void BeginAnimation(DependencyObject obj, DependencyProperty property, Timeline animation)
{
string propertyName;
2017-08-04 21:38:58 +02:00
if (properties.TryGetValue(property, out propertyName))
{
Storyboard.SetTargetProperty(animation, propertyName);
Storyboard.SetTarget(animation, obj);
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
}
}
}
}