仿windows8 开始菜单 实现HubTileBase 以及仿鲜果联播实现 PulsingTile(脉冲磁贴)
http://blog.csdn.net/wangrenzhu2011/article/details/8750820 (转)
本文章将以如何实现 开始菜单上的tile 为主。
该控件代码经过测试可直接使用。
tile 在我的思路中分为了 3层。
基于ContentControl实现HeaderedContentControl 用于增加Tile种的内容标题
在HeaderedContentControl 的基础上 实现 3d变换 根据触点方向触发不同动画。
实现HubTileBase
在HubTileBase 下我们可以实现多种磁贴
如liveTile(实时反馈) MosaicTile(仿wp8 风格) PulsingTile(脉冲)等等。。
以下将以PulsingTile 代码为主 来介绍
- public class HeaderedContentControl : ContentControl
- {
- public static readonly DependencyProperty HeaderProperty =
- DependencyProperty.Register("Header", typeof(object), typeof(HeaderedContentControl), new PropertyMetadata(null));
- public static readonly DependencyProperty HeaderStyleProperty =
- DependencyProperty.Register("HeaderStyle", typeof(Style), typeof(HeaderedContentControl), new PropertyMetadata(null));
- public static readonly DependencyProperty HeaderTemplateProperty =
- DependencyProperty.Register("HeaderTemplate", typeof(DataTemplate), typeof(HeaderedContentControl), new PropertyMetadata(null));
- public static readonly DependencyProperty HeaderTemplateSelectorProperty =
- DependencyProperty.Register("HeaderTemplateSelector", typeof(DataTemplateSelector), typeof(HeaderedContentControl), new PropertyMetadata(null));
- public HeaderedContentControl()
- {
- this.DefaultStyleKey = typeof(HeaderedContentControl);
- }
- public object Header
- {
- get
- {
- return base.GetValue(HeaderProperty);
- }
- set
- {
- base.SetValue(HeaderProperty, value);
- }
- }
- public Style HeaderStyle
- {
- get
- {
- return (Style)base.GetValue(HeaderStyleProperty);
- }
- set
- {
- base.SetValue(HeaderStyleProperty, value);
- }
- }
- public DataTemplate HeaderTemplate
- {
- get
- {
- return (DataTemplate)base.GetValue(HeaderTemplateProperty);
- }
- set
- {
- base.SetValue(HeaderTemplateProperty, value);
- }
- }
- public DataTemplateSelector HeaderTemplateSelector
- {
- get
- {
- return (DataTemplateSelector)base.GetValue(HeaderTemplateSelectorProperty);
- }
- set
- {
- base.SetValue(HeaderTemplateSelectorProperty, value);
- }
- }
- }
- public class HubTileBase : HeaderedContentControl
- {
- public static readonly DependencyProperty AccentBrushProperty = DependencyProperty.Register("AccentBrush", typeof(Brush), typeof(HubTileBase), new PropertyMetadata(null));
- public static readonly DependencyProperty GroupNameProperty = DependencyProperty.Register("GroupName", typeof(string), typeof(HubTileBase), new PropertyMetadata(string.Empty));
- public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(Windows.UI.Xaml.Media.ImageSource), typeof(HubTileBase), new PropertyMetadata(null));
- public static readonly DependencyProperty IsFrozenProperty = DependencyProperty.Register("IsFrozen", typeof(bool), typeof(HubTileBase), new PropertyMetadata((bool)false, OnIsFrozenChanged));
- public static readonly DependencyProperty OverrideDefaultStatesProperty = DependencyProperty.Register("OverrideDefaultStates", typeof(bool), typeof(HubTileBase), new PropertyMetadata((bool)false));
- private PointerDirection pointerdirection;
- private bool pointerover;
- private bool pointerpressed;
- public static readonly DependencyProperty RotationDepthProperty = DependencyProperty.Register("RotationDepth", typeof(double), typeof(HubTileBase), new PropertyMetadata((double)20.0));
- public static readonly DependencyProperty ScaleDepthProperty = DependencyProperty.Register("ScaleDepth", typeof(double), typeof(HubTileBase), new PropertyMetadata((double)0.9));
- private Storyboard storyboard;
- public static readonly DependencyProperty TilePressDurationProperty = DependencyProperty.Register("TilePressDuration", typeof(TimeSpan), typeof(HubTileBase), new PropertyMetadata(TimeSpan.FromSeconds((double)0.1)));
- public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(object), typeof(HubTileBase), new PropertyMetadata(null));
- public static readonly DependencyProperty TitleStyleProperty = DependencyProperty.Register("TitleStyle", typeof(Style), typeof(HubTileBase), new PropertyMetadata(null));
- private Timeline BuildAnimation(PointerDirection direction)
- {
- DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
- Storyboard.SetTarget(frames, this);
- if (direction != PointerDirection.Center)
- {
- PlaneProjection projection2 = new PlaneProjection();
- projection2.CenterOfRotationZ = 0.0;
- PlaneProjection projection = projection2;
- EasingDoubleKeyFrame frame3 = new EasingDoubleKeyFrame();
- frame3.KeyTime = ((KeyTime)TimeSpan.FromSeconds((double)0.0));
- frame3.Value = 0.0;
- EasingDoubleKeyFrame frame = frame3;
- EasingDoubleKeyFrame frame4 = new EasingDoubleKeyFrame();
- frame4.KeyTime = ((KeyTime)this.TilePressDuration);
- EasingDoubleKeyFrame frame2 = frame4;
- frames.KeyFrames.Add(frame);
- frames.KeyFrames.Add(frame2);
- if ((direction == PointerDirection.Left) || (direction == PointerDirection.Bottom))
- {
- frame2.Value = this.RotationDepth;
- }
- else if ((direction == PointerDirection.Top) || (direction == PointerDirection.Right))
- {
- frame2.Value = -this.RotationDepth;
- }
- if ((direction == PointerDirection.Top) || (direction == PointerDirection.Bottom))
- {
- Storyboard.SetTargetProperty(frames, "(UIElement.Projection).(PlaneProjection.RotationX)");
- }
- else if ((direction == PointerDirection.Left) || (direction == PointerDirection.Right))
- {
- Storyboard.SetTargetProperty(frames, "(UIElement.Projection).(PlaneProjection.RotationY)");
- }
- if (direction == PointerDirection.Bottom)
- {
- projection.CenterOfRotationX = 0.5;
- projection.CenterOfRotationY = 0.0;
- }
- else if (direction == PointerDirection.Top)
- {
- projection.CenterOfRotationX = (0.5);
- projection.CenterOfRotationY = (1.0);
- }
- else if (direction == PointerDirection.Left)
- {
- projection.CenterOfRotationX = (1.0);
- projection.CenterOfRotationY = (0.5);
- }
- else if (direction == PointerDirection.Right)
- {
- projection.CenterOfRotationX = (0.0);
- projection.CenterOfRotationY = (0.5);
- }
- base.Projection = (projection);
- }
- return frames;
- }
- private Timeline BuildScaleXAnimation()
- {
- DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
- Storyboard.SetTarget(frames, this);
- Storyboard.SetTargetProperty(frames, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
- EasingDoubleKeyFrame frame3 = new EasingDoubleKeyFrame();
- frame3.KeyTime = ((KeyTime)TimeSpan.FromSeconds((double)0.0));
- frame3.Value = (1.0);
- EasingDoubleKeyFrame frame = frame3;
- EasingDoubleKeyFrame frame4 = new EasingDoubleKeyFrame();
- frame4.KeyTime = ((KeyTime)this.TilePressDuration);
- frame4.Value = (this.ScaleDepth);
- EasingDoubleKeyFrame frame2 = frame4;
- frames.KeyFrames.Add(frame);
- frames.KeyFrames.Add(frame2);
- CompositeTransform transform = new CompositeTransform();
- base.RenderTransformOrigin = (new Point(0.5, 0.5));
- base.RenderTransform = (transform);
- return frames;
- }
- private Timeline BuildScaleYAnimation()
- {
- DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
- Storyboard.SetTarget(frames, this);
- Storyboard.SetTargetProperty(frames, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
- EasingDoubleKeyFrame frame3 = new EasingDoubleKeyFrame();
- frame3.KeyTime = ((KeyTime)TimeSpan.FromSeconds((double)0.0));
- frame3.Value = (1.0);
- EasingDoubleKeyFrame frame = frame3;
- EasingDoubleKeyFrame frame4 = new EasingDoubleKeyFrame();
- frame4.KeyTime = ((KeyTime)this.TilePressDuration);
- frame4.Value = (this.ScaleDepth);
- EasingDoubleKeyFrame frame2 = frame4;
- frames.KeyFrames.Add(frame);
- frames.KeyFrames.Add(frame2);
- CompositeTransform transform = new CompositeTransform();
- base.RenderTransform = (transform);
- base.RenderTransformOrigin = (new Point(0.5, 0.5));
- return frames;
- }
- private void ExecutePointerReleased()
- {
- if (this.pointerpressed)
- {
- if (this.OverrideDefaultStates)
- {
- if (this.pointerover)
- {
- VisualStateManager.GoToState(this, "PointerOver", true);
- }
- else
- {
- VisualStateManager.GoToState(this, "Normal", true);
- }
- }
- else if (this.storyboard != null)
- {
- if (this.pointerdirection != PointerDirection.Center)
- {
- DoubleAnimationUsingKeyFrames frames = this.storyboard.Children[0] as DoubleAnimationUsingKeyFrames;
- if (frames != null)
- {
- EasingDoubleKeyFrame frame = frames.KeyFrames[0] as EasingDoubleKeyFrame;
- EasingDoubleKeyFrame frame2 = frames.KeyFrames[1] as EasingDoubleKeyFrame;
- frame.Value = (frame2.Value);
- frame2.Value = (0.0);
- }
- }
- else
- {
- DoubleAnimationUsingKeyFrames frames2 = this.storyboard.Children[0] as DoubleAnimationUsingKeyFrames;
- DoubleAnimationUsingKeyFrames frames3 = this.storyboard.Children[1] as DoubleAnimationUsingKeyFrames;
- if (frames2 != null)
- {
- EasingDoubleKeyFrame frame3 = frames2.KeyFrames[0] as EasingDoubleKeyFrame;
- EasingDoubleKeyFrame frame4 = frames2.KeyFrames[1] as EasingDoubleKeyFrame;
- frame3.Value = (frame4.Value);
- frame4.Value = (1.0);
- }
- if (frames3 != null)
- {
- EasingDoubleKeyFrame frame5 = frames3.KeyFrames[0] as EasingDoubleKeyFrame;
- EasingDoubleKeyFrame frame6 = frames3.KeyFrames[1] as EasingDoubleKeyFrame;
- frame5.Value = (frame6.Value);
- frame6.Value = (1.0);
- }
- }
- this.storyboard.Begin();
- }
- }
- this.pointerpressed = false;
- }
- protected virtual void OnIsFrozenChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- private static void OnIsFrozenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
- {
- HubTileBase base2 = sender as HubTileBase;
- if (base2 != null)
- {
- base2.OnIsFrozenChanged(e);
- }
- }
- protected override void OnPointerEntered(PointerRoutedEventArgs e)
- {
- this.pointerover = true;
- VisualStateManager.GoToState(this, "PointerOver", true);
- base.OnPointerEntered(e);
- }
- protected override void OnPointerExited(PointerRoutedEventArgs e)
- {
- if (this.pointerpressed)
- {
- this.ExecutePointerReleased();
- }
- this.pointerover = false;
- VisualStateManager.GoToState(this, "Normal", true);
- base.OnPointerExited(e);
- }
- protected override void OnPointerPressed(PointerRoutedEventArgs e)
- {
- this.pointerpressed = true;
- if (this.OverrideDefaultStates)
- {
- VisualStateManager.GoToState(this, "PointerPressed", true);
- }
- else
- {
- PointerPoint currentpoint = e.GetCurrentPoint(this);
- var point = currentpoint.Position;
- double num = base.ActualWidth / 3.0;
- double num2 = base.ActualHeight / 3.0;
- Dictionary<PointerDirection, Rect> pieces = new Dictionary<PointerDirection, Rect>();
- pieces.Add(PointerDirection.TopLeft, new Rect(0.0, 0.0, num, num2));
- pieces.Add(PointerDirection.Top, new Rect(num, 0.0, num, num2));
- pieces.Add(PointerDirection.TopRight, new Rect(num * 2.0, 0.0, num, num2));
- pieces.Add(PointerDirection.Left, new Rect(0.0, num2, num, num2));
- pieces.Add(PointerDirection.Center, new Rect(num, num2, num, num2));
- pieces.Add(PointerDirection.Right, new Rect(num * 2.0, num2, num, num2));
- pieces.Add(PointerDirection.BottomLeft, new Rect(0.0, num2 * 2.0, num, num2));
- pieces.Add(PointerDirection.Bottom, new Rect(num, num2 * 2.0, num, num2));
- pieces.Add(PointerDirection.BottomRight, new Rect(num * 2.0, num2 * 2.0, num, num2));
- this.pointerdirection =
- (from _direction in pieces.Keys
- where pieces[_direction].Contains(point)
- select _direction).FirstOrDefault();
- this.storyboard = new Storyboard();
- if (this.pointerdirection <= PointerDirection.Center)
- {
- if (this.pointerdirection == PointerDirection.Center)
- {
- Timeline timeline = this.BuildScaleXAnimation();
- Timeline timeline2 = this.BuildScaleYAnimation();
- this.storyboard.Children.Add(timeline);
- this.storyboard.Children.Add(timeline2);
- this.storyboard.Begin();
- }
- else
- {
- Timeline timeline3 = this.BuildAnimation(this.pointerdirection);
- this.storyboard.Children.Add(timeline3);
- this.storyboard.Begin();
- }
- }
- else if (this.pointerdirection == PointerDirection.TopLeft)
- {
- if (currentpoint.Position.X > currentpoint.Position.Y)
- {
- Timeline timeline4 = this.BuildAnimation(PointerDirection.Top);
- this.storyboard.Children.Add(timeline4);
- this.storyboard.Begin();
- }
- else
- {
- Timeline timeline5 = this.BuildAnimation(PointerDirection.Left);
- this.storyboard.Children.Add(timeline5);
- this.storyboard.Begin();
- }
- }
- else if (this.pointerdirection == PointerDirection.TopRight)
- {
- if (currentpoint.Position.Y > (num2 - (currentpoint.Position.X - (num * 2.0))))
- {
- Timeline timeline6 = this.BuildAnimation(PointerDirection.Right);
- this.storyboard.Children.Add(timeline6);
- this.storyboard.Begin();
- }
- else
- {
- Timeline timeline7 = this.BuildAnimation(PointerDirection.Top);
- this.storyboard.Children.Add(timeline7);
- this.storyboard.Begin();
- }
- }
- else if (this.pointerdirection == PointerDirection.BottomLeft)
- {
- if ((currentpoint.Position.Y - (num2 * 2.0)) > (num2 - currentpoint.Position.X))
- {
- Timeline timeline8 = this.BuildAnimation(PointerDirection.Bottom);
- this.storyboard.Children.Add(timeline8);
- this.storyboard.Begin();
- }
- else
- {
- Timeline timeline9 = this.BuildAnimation(PointerDirection.Left);
- this.storyboard.Children.Add(timeline9);
- this.storyboard.Begin();
- }
- }
- else if (currentpoint.Position.X > currentpoint.Position.Y)
- {
- Timeline timeline10 = this.BuildAnimation(PointerDirection.Right);
- this.storyboard.Children.Add(timeline10);
- this.storyboard.Begin();
- }
- else
- {
- Timeline timeline11 = this.BuildAnimation(PointerDirection.Bottom);
- this.storyboard.Children.Add(timeline11);
- this.storyboard.Begin();
- }
- }
- base.OnPointerPressed(e);
- }
- protected override void OnPointerReleased(PointerRoutedEventArgs e)
- {
- this.ExecutePointerReleased();
- base.OnPointerReleased(e);
- }
- public Brush AccentBrush
- {
- get
- {
- return (Brush)base.GetValue(AccentBrushProperty);
- }
- set
- {
- base.SetValue(AccentBrushProperty, value);
- }
- }
- public string GroupName
- {
- get
- {
- return (string)((string)base.GetValue(GroupNameProperty));
- }
- set
- {
- base.SetValue(GroupNameProperty, value);
- }
- }
- public Windows.UI.Xaml.Media.ImageSource ImageSource
- {
- get
- {
- return (Windows.UI.Xaml.Media.ImageSource)base.GetValue(ImageSourceProperty);
- }
- set
- {
- base.SetValue(ImageSourceProperty, value);
- }
- }
- public bool IsFrozen
- {
- get
- {
- return (bool)((bool)base.GetValue(IsFrozenProperty));
- }
- set
- {
- base.SetValue(IsFrozenProperty, (bool)value);
- }
- }
- public bool OverrideDefaultStates
- {
- get
- {
- return (bool)((bool)base.GetValue(OverrideDefaultStatesProperty));
- }
- set
- {
- base.SetValue(OverrideDefaultStatesProperty, (bool)value);
- }
- }
- public double RotationDepth
- {
- get
- {
- return (double)((double)base.GetValue(RotationDepthProperty));
- }
- set
- {
- base.SetValue(RotationDepthProperty, (double)value);
- }
- }
- public double ScaleDepth
- {
- get
- {
- return (double)((double)base.GetValue(ScaleDepthProperty));
- }
- set
- {
- base.SetValue(ScaleDepthProperty, (double)value);
- }
- }
- public TimeSpan TilePressDuration
- {
- get
- {
- return (TimeSpan)base.GetValue(TilePressDurationProperty);
- }
- set
- {
- base.SetValue(TilePressDurationProperty, value);
- }
- }
- public object Title
- {
- get
- {
- return base.GetValue(TitleProperty);
- }
- set
- {
- base.SetValue(TitleProperty, value);
- }
- }
- public Style TitleStyle
- {
- get
- {
- return (Style)base.GetValue(TitleStyleProperty);
- }
- set
- {
- base.SetValue(TitleStyleProperty, value);
- }
- }
- }
- public static class HubTileService
- {
- private static List<WeakReference> Tiles = new List<WeakReference>();
- internal static void Dequeue(HubTileBase tile)
- {
- foreach (WeakReference reference in Tiles)
- {
- if (reference.Target == tile)
- {
- Tiles.Remove(reference);
- break;
- }
- }
- }
- internal static void Enqueue(HubTileBase tile)
- {
- WeakReference reference = new WeakReference(tile, false);
- Tiles.Add(reference);
- }
- public static void Freeze(HubTileBase tile)
- {
- foreach (WeakReference reference in Tiles)
- {
- if (reference.Target == tile)
- {
- HubTileBase base2 = reference.Target as HubTileBase;
- base2.IsFrozen = true;
- break;
- }
- }
- }
- public static void Freeze(string groupname)
- {
- using (List<WeakReference>.Enumerator enumerator = Tiles.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- HubTileBase base2 = enumerator.Current.Target as HubTileBase;
- if ((base2 != null) && (base2.GroupName == groupname))
- {
- base2.IsFrozen = false;
- }
- }
- }
- }
- public static void UnFreeze(HubTileBase tile)
- {
- foreach (WeakReference reference in Tiles)
- {
- if (reference.Target == tile)
- {
- HubTileBase base2 = reference.Target as HubTileBase;
- base2.IsFrozen = false;
- break;
- }
- }
- }
- public static void UnFreeze(string groupname)
- {
- using (List<WeakReference>.Enumerator enumerator = Tiles.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- HubTileBase base2 = enumerator.Current.Target as HubTileBase;
- if ((base2 != null) && (base2.GroupName == groupname))
- {
- base2.IsFrozen = false;
- }
- }
- }
- }
- }
- public enum PointerDirection
- {
- Left,
- Top,
- Right,
- Bottom,
- Center,
- TopLeft,
- TopRight,
- BottomLeft,
- BottomRight
- }
- public class PulsingTile : HubTileBase
- {
- protected ContentPresenter PART_Content;
- public static readonly DependencyProperty PulseDurationProperty = DependencyProperty.Register("PulseDuration", typeof(TimeSpan), typeof(PulsingTile), new PropertyMetadata(TimeSpan.FromSeconds((double)4.0), new PropertyChangedCallback(OnValueChanged)));
- public static readonly DependencyProperty PulseScaleProperty = DependencyProperty.Register("PulseScale", typeof(double), typeof(PulsingTile), new PropertyMetadata((double)1.0, new PropertyChangedCallback(OnValueChanged)));
- private Storyboard pulseStroyboard;
- public static readonly DependencyProperty RadiusXProperty = DependencyProperty.Register("RadiusX", typeof(double), typeof(PulsingTile), new PropertyMetadata((double)0.0, new PropertyChangedCallback(OnValueChanged)));
- public static readonly DependencyProperty RadiusYProperty = DependencyProperty.Register("RadiusY", typeof(double), typeof(PulsingTile), new PropertyMetadata((double)0.0, new PropertyChangedCallback(OnValueChanged)));
- private Storyboard roatationStroyboard;
- public static readonly DependencyProperty TranslateDurationProperty = DependencyProperty.Register("TranslateDuration", typeof(TimeSpan), typeof(PulsingTile), new PropertyMetadata(TimeSpan.FromSeconds((double)4.0), new PropertyChangedCallback(OnValueChanged)));
- public PulsingTile()
- {
- base.DefaultStyleKey = (typeof(PulsingTile));
- PulsingTile tile = this;
- this.Loaded += this.OnLoaded;
- }
- private void AnimateContent()
- {
- if (this.PART_Content != null)
- {
- RectangleGeometry geometry = new RectangleGeometry();
- geometry.Rect = (new Rect(0.0, 0.0, base.ActualWidth, base.ActualHeight));
- base.Clip = (geometry);
- this.PART_Content.RenderTransform = (new CompositeTransform());
- this.PART_Content.RenderTransformOrigin = (new Point(0.5, 0.5));
- this.PART_Content.Visibility = Windows.UI.Xaml.Visibility.Visible;
- DoubleAnimationUsingKeyFrames frames = this.BuildXTimeLine(this.RadiusX, this.RadiusY);
- DoubleAnimationUsingKeyFrames frames2 = this.BuildYTimeLine(this.RadiusX, this.RadiusY);
- this.roatationStroyboard = new Storyboard();
- RepeatBehavior behavior = new RepeatBehavior();
- behavior.Type = (RepeatBehaviorType.Forever);
- this.roatationStroyboard.RepeatBehavior = (behavior);
- this.roatationStroyboard.Children.Add(frames);
- this.roatationStroyboard.Children.Add(frames2);
- Storyboard.SetTarget(frames, this.PART_Content);
- Storyboard.SetTarget(frames2, this.PART_Content);
- Storyboard.SetTargetProperty(frames, "(UIElement.RenderTransform).(CompositeTransform.TranslateX)");
- Storyboard.SetTargetProperty(frames2, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");
- DoubleAnimationUsingKeyFrames frames3 = this.BuildPulseXTimeLine(this.PulseScale);
- DoubleAnimationUsingKeyFrames frames4 = this.BuildPulseYTimeLine(this.PulseScale);
- this.pulseStroyboard = new Storyboard();
- this.pulseStroyboard.AutoReverse = (true);
- this.pulseStroyboard.SpeedRatio = (0.4);
- RepeatBehavior behavior2 = new RepeatBehavior();
- behavior2.Type = (RepeatBehaviorType.Forever);
- this.pulseStroyboard.RepeatBehavior = (behavior2);
- this.pulseStroyboard.Children.Add(frames3);
- this.pulseStroyboard.Children.Add(frames4);
- Storyboard.SetTarget(frames3, this.PART_Content);
- Storyboard.SetTarget(frames4, this.PART_Content);
- Storyboard.SetTargetProperty(frames3, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
- Storyboard.SetTargetProperty(frames4, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
- this.pulseStroyboard.Begin();
- this.roatationStroyboard.Begin();
- }
- }
- private DoubleAnimationUsingKeyFrames BuildPulseXTimeLine(double pulseScale)
- {
- TimeSpan pulseDuration = this.PulseDuration;
- SplineDoubleKeyFrame frame = new SplineDoubleKeyFrame();
- frame.Value = (1.0);
- frame.KeyTime = ((KeyTime)TimeSpan.FromSeconds((double)0.0));
- EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame();
- frame2.Value = (pulseScale);
- frame2.KeyTime = (KeyTime.FromTimeSpan(this.PulseDuration));
- SineEase ease = new SineEase();
- ease.EasingMode = EasingMode.EaseOut;
- frame2.EasingFunction = (ease);
- DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
- frames.KeyFrames.Add(frame);
- frames.KeyFrames.Add(frame2);
- return frames;
- }
- private DoubleAnimationUsingKeyFrames BuildPulseYTimeLine(double pulseScale)
- {
- TimeSpan pulseDuration = this.PulseDuration;
- SplineDoubleKeyFrame frame = new SplineDoubleKeyFrame();
- frame.Value = (1.0);
- frame.KeyTime = ((KeyTime)TimeSpan.FromSeconds((double)0.0));
- EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame();
- frame2.Value = (pulseScale);
- frame2.KeyTime = (KeyTime.FromTimeSpan(this.PulseDuration));
- SineEase ease = new SineEase();
- ease.EasingMode = EasingMode.EaseOut;
- frame2.EasingFunction = (ease);
- DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
- frames.KeyFrames.Add(frame);
- frames.KeyFrames.Add(frame2);
- return frames;
- }
- private DoubleAnimationUsingKeyFrames BuildXTimeLine(double radiusx, double radiusy)
- {
- TimeSpan translateDuration = this.TranslateDuration;
- DiscreteDoubleKeyFrame frame = new DiscreteDoubleKeyFrame();
- frame.Value = (0.0);
- frame.KeyTime = ((KeyTime)TimeSpan.FromSeconds((double)0.0));
- EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame();
- frame2.Value = (radiusx);
- frame2.KeyTime = (KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double)(translateDuration.TotalSeconds / 4.0))));
- SineEase ease = new SineEase();
- ease.EasingMode = EasingMode.EaseIn;
- frame2.EasingFunction = (ease);
- EasingDoubleKeyFrame frame3 = new EasingDoubleKeyFrame();
- frame3.Value = (0.0);
- frame3.KeyTime = (KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double)(translateDuration.TotalSeconds / 2.0))));
- SineEase ease2 = new SineEase();
- ease2.EasingMode = EasingMode.EaseInOut;
- frame3.EasingFunction = ease2;
- EasingDoubleKeyFrame frame4 = new EasingDoubleKeyFrame();
- frame4.Value = (-radiusx);
- frame4.KeyTime = (KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double)((translateDuration.TotalSeconds * 3.0) / 4.0))));
- SineEase ease3 = new SineEase();
- ease3.EasingMode = EasingMode.EaseIn;
- frame4.EasingFunction = (ease3);
- EasingDoubleKeyFrame frame5 = new EasingDoubleKeyFrame();
- frame5.Value = (0.0);
- frame5.KeyTime = (KeyTime.FromTimeSpan(translateDuration));
- SineEase ease4 = new SineEase();
- ease4.EasingMode = EasingMode.EaseInOut;
- frame5.EasingFunction = (ease4);
- DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
- frames.KeyFrames.Add(frame);
- frames.KeyFrames.Add(frame2);
- frames.KeyFrames.Add(frame3);
- frames.KeyFrames.Add(frame4);
- frames.KeyFrames.Add(frame5);
- return frames;
- }
- private DoubleAnimationUsingKeyFrames BuildYTimeLine(double radiusx, double radiusy)
- {
- TimeSpan translateDuration = this.TranslateDuration;
- DiscreteDoubleKeyFrame frame = new DiscreteDoubleKeyFrame();
- frame.Value = (0.0);
- frame.KeyTime = ((KeyTime)TimeSpan.FromSeconds((double)0.0));
- EasingDoubleKeyFrame frame2 = new EasingDoubleKeyFrame();
- frame2.Value = (this.RadiusY);
- frame2.KeyTime = (KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double)(translateDuration.TotalSeconds / 4.0))));
- SineEase ease = new SineEase();
- ease.EasingMode = EasingMode.EaseIn;
- frame2.EasingFunction = (ease);
- EasingDoubleKeyFrame frame3 = new EasingDoubleKeyFrame();
- frame3.Value = (2.0 * this.RadiusY);
- frame3.KeyTime = (KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double)(translateDuration.TotalSeconds / 2.0))));
- SineEase ease2 = new SineEase();
- ease2.EasingMode = EasingMode.EaseIn;
- frame3.EasingFunction = (ease2);
- EasingDoubleKeyFrame frame4 = new EasingDoubleKeyFrame();
- frame4.Value = (radiusy);
- frame4.KeyTime = (KeyTime.FromTimeSpan(TimeSpan.FromSeconds((double)((translateDuration.TotalSeconds * 3.0) / 4.0))));
- SineEase ease3 = new SineEase();
- ease3.EasingMode = EasingMode.EaseInOut;
- frame4.EasingFunction = (ease3);
- EasingDoubleKeyFrame frame5 = new EasingDoubleKeyFrame();
- frame5.Value = (0.0);
- frame5.KeyTime = (KeyTime.FromTimeSpan(translateDuration));
- SineEase ease4 = new SineEase();
- ease4.EasingMode = EasingMode.EaseIn;
- frame5.EasingFunction = (ease4);
- DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();
- frames.KeyFrames.Add(frame);
- frames.KeyFrames.Add(frame2);
- frames.KeyFrames.Add(frame3);
- frames.KeyFrames.Add(frame4);
- frames.KeyFrames.Add(frame5);
- return frames;
- }
- protected override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
- this.PART_Content = base.GetTemplateChild("PART_Content") as ContentPresenter;
- }
- protected override void OnIsFrozenChanged(DependencyPropertyChangedEventArgs e)
- {
- if (base.IsFrozen)
- {
- if (this.pulseStroyboard != null)
- {
- this.pulseStroyboard.Stop();
- }
- if (this.roatationStroyboard != null)
- {
- this.roatationStroyboard.Stop();
- }
- }
- else
- {
- if (this.pulseStroyboard != null)
- {
- this.pulseStroyboard.Begin();
- }
- if (this.roatationStroyboard != null)
- {
- this.roatationStroyboard.Begin();
- }
- }
- }
- private void OnLoaded(object sender, RoutedEventArgs e)
- {
- HubTileService.Enqueue(this);
- PulsingTile tile = this;
- this.Loaded += PulsingTile_Unloaded;
- this.StartAnimation();
- }
- private static void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
- {
- PulsingTile tile = sender as PulsingTile;
- if (tile != null)
- {
- tile.StopAnimation();
- tile.StartAnimation();
- }
- }
- private void PulsingTile_Unloaded(object sender, RoutedEventArgs e)
- {
- HubTileService.Dequeue(this);
- this.Unloaded -= PulsingTile_Unloaded;
- }
- private void StartAnimation()
- {
- this.AnimateContent();
- }
- private void StopAnimation()
- {
- if (this.pulseStroyboard != null)
- {
- this.pulseStroyboard.Stop();
- }
- if (this.roatationStroyboard != null)
- {
- this.roatationStroyboard.Stop();
- }
- }
- public TimeSpan PulseDuration
- {
- get
- {
- return (TimeSpan)base.GetValue(PulseDurationProperty);
- }
- set
- {
- base.SetValue(PulseDurationProperty, value);
- }
- }
- public double PulseScale
- {
- get
- {
- return (double)((double)base.GetValue(PulseScaleProperty));
- }
- set
- {
- base.SetValue(PulseScaleProperty, (double)value);
- }
- }
- public double RadiusX
- {
- get
- {
- return (double)((double)base.GetValue(RadiusXProperty));
- }
- set
- {
- base.SetValue(RadiusXProperty, (double)value);
- }
- }
- public double RadiusY
- {
- get
- {
- return (double)((double)base.GetValue(RadiusYProperty));
- }
- set
- {
- base.SetValue(RadiusYProperty, (double)value);
- }
- }
- public TimeSpan TranslateDuration
- {
- get
- {
- return (TimeSpan)base.GetValue(TranslateDurationProperty);
- }
- set
- {
- base.SetValue(TranslateDurationProperty, value);
- }
- }
- }
- <ResourceDictionary
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:PulsingTile="using:WinRTXamlToolkit.Controls">
- <SolidColorBrush x:Key="AccentBrush" Color="#FF1FAEFF" />
- <DataTemplate x:Key="ImageTileContentTemplate">
- <Grid>
- <Rectangle Fill="{Binding Background}"/>
- <Rectangle Fill="White" Opacity="{Binding Opacity}"/>
- <Image Source="{Binding Image}" Width="{Binding ImageWidth}" Height="{Binding ImageHeight}"
- HorizontalAlignment="{Binding HorizontalImageAlignment}"
- VerticalAlignment="{Binding VerticalImageAlignment}" Stretch="UniformToFill"/>
- </Grid>
- </DataTemplate>
- <Style TargetType="ContentControl" x:Key="DefaultHeaderStyle">
- <Setter Property="HorizontalAlignment" Value="Left"/>
- <Setter Property="VerticalAlignment" Value="Bottom"/>
- <Setter Property="Margin" Value="10 5"/>
- <Setter Property="FontSize" Value="18"/>
- </Style>
- <Style TargetType="ContentControl" x:Key="DefaultTitleStyle">
- <Setter Property="HorizontalAlignment" Value="Stretch"/>
- <Setter Property="VerticalAlignment" Value="Top"/>
- <Setter Property="Margin" Value="5"/>
- <Setter Property="FontSize" Value="10"/>
- </Style>
- <Style TargetType="PulsingTile:PulsingTile" >
- <Setter Property="Padding" Value="3"/>
- <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
- <Setter Property="VerticalContentAlignment" Value="Stretch"/>
- <Setter Property="HeaderStyle" Value="{StaticResource DefaultHeaderStyle}"/>
- <Setter Property="TitleStyle" Value="{StaticResource DefaultTitleStyle}"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="PulsingTile:PulsingTile">
- <Grid x:Name="PART_Layout">
- <VisualStateManager.VisualStateGroups>
- <VisualStateGroup x:Name="CommonStates">
- <VisualState x:Name="Normal"/>
- <VisualState x:Name="PointerOver">
- <Storyboard>
- <DoubleAnimation Duration="0" To="0.28"
- Storyboard.TargetProperty="Opacity"
- Storyboard.TargetName="PointerOveRect"/>
- </Storyboard>
- </VisualState>
- <VisualState x:Name="PointerPressed">
- </VisualState>
- </VisualStateGroup>
- </VisualStateManager.VisualStateGroups>
- <Rectangle x:Name="PointerOveRect"
- Fill="{StaticResource ApplicationForegroundThemeBrush}"
- Opacity="0" Margin="-2"/>
- <Border BorderBrush="{TemplateBinding BorderBrush}"
- BorderThickness="{TemplateBinding BorderThickness}"
- Background="{TemplateBinding Background}" Margin="{TemplateBinding Padding}"
- x:Name="PART_Border">
- <Grid Margin="{TemplateBinding Padding}" >
- <ContentPresenter
- x:Name="PART_Content"
- HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
- VerticalAlignment="{TemplateBinding VerticalAlignment}" />
- <ContentControl Content="{TemplateBinding Title}"
- Style="{TemplateBinding TitleStyle}"/>
- <ContentControl Content="{TemplateBinding Header}"
- Style="{TemplateBinding HeaderStyle}"
- ContentTemplate="{TemplateBinding HeaderTemplate}"
- ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
- />
- </Grid>
- </Border>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- </ResourceDictionary>
以上是主体代码。可以将其复制到项目中编译后可用。
使用方式:
- <tools:PulsingTile
- HorizontalAlignment="Stretch"
- Width="423423"
- Height="43423"
- d:DesignWidth="200"
- d:DesignHeight="200"
- Foreground="White"
- RadiusX="0"
- RadiusY="0"
- Title="123123123123"
- PulseDuration="0:0:5"
- PulseScale="2"
- VerticalAlignment="Stretch">
- <Image Source="XXXXXXXXXXXXXXXXX"></Image>
- </tools:PulsingTile>
最终效果: 该磁贴会根据 时间 放大倍数 等参数 定时脉冲缩放
仿windows8 开始菜单 实现HubTileBase 以及仿鲜果联播实现 PulsingTile(脉冲磁贴)的更多相关文章
- iOS仿京东分类菜单之UICollectionView内容
在上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列 ...
- Android 打造炫目的圆形菜单 秒秒钟高仿建行圆形菜单
原文:Android 打造炫目的圆形菜单 秒秒钟高仿建行圆形菜单 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/43131133, ...
- 仿联想商城laravel实战---1、仿联想商城需求和数据库设计(lavarel如何搭建项目)
仿联想商城laravel实战---1.仿联想商城需求和数据库设计(lavarel如何搭建项目) 一.总结 一句话总结: composer引入lavarel.配置域名.配置apache 1.项目名 le ...
- jQuery仿京东无限级菜单HoverTree
官方网址:http://keleyi.com/jq/hovertree/ 效果图: 看了上面效果图,你或许已经明白为什么是仿京东菜单.如果还不明白,请访问http://list.jd.com/list ...
- 仿京东树形菜单插件hovertree
hovertree是一个仿京东的树形菜单jquery插件,暂时有银色和绿色两种. 官方网址:http://keleyi.com/jq/hovertree/欢迎下载使用 查看绿色效果:http://ke ...
- Android开发:仿美团下拉列表菜单,帮助类,复用简单
近期在项目中须要用到下拉菜单.公司比較推崇美团的下拉菜单,于是要实现该功能.想着.这个功能应该是一个常常会用到的.于是何不写一个帮助类,仅仅要往这个类里面传入特定的參数,既能够实现下来菜单,并且还能够 ...
- android仿网易云音乐引导页、仿书旗小说Flutter版、ViewPager切换、爆炸菜单、风扇叶片效果等源码
Android精选源码 复现网易云音乐引导页效果 高仿书旗小说 Flutter版,支持iOS.Android Android Srt和Ass字幕解析器 Material Design ViewPage ...
- iOS仿QQ侧滑菜单、登录按钮动画、仿斗鱼直播APP、城市选择器、自动布局等源码
iOS精选源码 QQ侧滑菜单,右滑菜单,QQ展开菜单,QQ好友分组 登录按钮 3分钟快捷创建高性能轮播图 ScrollView嵌套ScrolloView(UITableView .UICollecti ...
- 仿QQ侧滑菜单<大自然的搬运工-代码不是我的>
1.记录下效果图 2.二个工具类 package myapplication.com.myapplicationfortest.utils; import android.util.Log; /** ...
随机推荐
- localResizeIMG
http://think2011.net/localResizeIMG/test/ 演示一下 自己试试 点我直接进入演示页面 说明 在客户端压缩好要上传的图片可以节省带宽更快的发送给后端,特别适合在移 ...
- nGrinder性能测试平台搭建(LVS压力测试)
1. nGrinder是什么 nGrinder是一个免费的.开放源代码的Web性能测试平台.运行在应用中间件服务器中运行.它由一个控制端和多个代理端组成.通过控制端(浏览器访问)建立测试场景,然后通过 ...
- ecshop的商品系统数据库整合
-- 表的结构 `ecs_shop_config` '全站配置信息表' 商店设置 `id` '全站配置信息自增id',`parent_id` '父节点id,取值于该表id字段的值',`co ...
- js ==与===区别(两个等号与三个等号)
1.对于string,number等基础类型,==和===是有区别的 1)不同类型间比较,==之比较“转化成同一类型后的值”看“值”是否相等,===如果类型不同,其结果就是不等 2)同类型比较,直接进 ...
- spring mvc form表单提交乱码
spring mvc form表单submit直接提交出现乱码.导致乱码一般是服务器端和页面之间编码不一致造成的.根据这一思路可以依次可以有以下方案. 1.jsp页面设置编码 <%@ page ...
- iOS 中添加lib型target库的依赖问题
今天在编码时遇到一个问题,总提示我找不到系统库文件. 我的项目结构类似下图 在TestLib中有引用CoreLocation库的类.但是CoreLocation库需要加在PhotoInfoDemo对象 ...
- Java与数据库类型对照表
数据库类型 Java类型 INTEGER int or java.lang.Integer BIGINT long or java.lang.Long SMALLINT short o ...
- 使用Memory Analyzer tool(MAT)分析内存泄漏(二)
转载自:http://www.blogjava.net/rosen/archive/2010/06/13/323522.html 前言的前言 写blog就是好,在大前提下可以想说什么写什么,不像投稿那 ...
- SharedPreferences&SQLite比较
SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置比如窗口状态,一般在Activity中 重载窗口状态onSaveInstanceState保存一般使 ...
- Android手势锁实现
最终效果如下 整体思路 a.自定义了一个RelativeLayout(GestureLockViewGroup)在里面会根据传入的每行的个数,生成多个GestureLockView(就是上面一个个小圈 ...