Improved BeginAnimation extension methods for UWP.

This commit is contained in:
ClemensF 2016-07-03 00:32:11 +02:00
parent 5011138446
commit da684bff95
2 changed files with 23 additions and 26 deletions

View file

@ -3,6 +3,7 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Collections.Generic;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.Xaml;
@ -26,38 +27,34 @@ namespace MapControl
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, DoubleAnimation animation)
{
animation.EnableDependentAnimation = true;
if (property == UIElement.OpacityProperty)
{
BeginAnimation(obj, "Opacity", animation);
}
else if (property == MapBase.ZoomLevelProperty)
{
BeginAnimation(obj, "ZoomLevel", animation);
}
else if (property == MapBase.HeadingProperty)
{
BeginAnimation(obj, "Heading", animation);
}
BeginAnimation(obj, property, (Timeline)animation);
}
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, PointAnimation animation)
{
animation.EnableDependentAnimation = true;
if (property == MapBase.CenterPointProperty)
{
BeginAnimation(obj, "CenterPoint", animation);
}
BeginAnimation(obj, property, (Timeline)animation);
}
private static void BeginAnimation(DependencyObject obj, string property, Timeline animation)
private static Dictionary<DependencyProperty, string> properties = new Dictionary<DependencyProperty, string>()
{
Storyboard.SetTargetProperty(animation, property);
Storyboard.SetTarget(animation, obj);
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
{ UIElement.OpacityProperty, "Opacity" },
{ MapBase.ZoomLevelProperty, "ZoomLevel" },
{ MapBase.HeadingProperty, "Heading" },
{ MapBase.CenterPointProperty, "CenterPoint" }
};
private static void BeginAnimation(DependencyObject obj, DependencyProperty property, Timeline animation)
{
string propertyName;
if (properties.TryGetValue(property, out propertyName))
{
Storyboard.SetTargetProperty(animation, propertyName);
Storyboard.SetTarget(animation, obj);
var storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
}
}
}
}

View file

@ -425,8 +425,8 @@ namespace MapControl
{
var p1 = mapTransform.Transform(southWest);
var p2 = mapTransform.Transform(northEast);
var lonScale = RenderSize.Width / (p2.X - p1.X) * 360d / (double)TileSource.TileSize;
var latScale = RenderSize.Height / (p2.Y - p1.Y) * 360d / (double)TileSource.TileSize;
var lonScale = RenderSize.Width / (p2.X - p1.X) * 360d / TileSource.TileSize;
var latScale = RenderSize.Height / (p2.Y - p1.Y) * 360d / TileSource.TileSize;
var lonZoom = Math.Log(lonScale, 2d);
var latZoom = Math.Log(latScale, 2d);