翻转切换效果。
完整代码如下: using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Interactivity;
using System.ComponentModel;
namespace FlipTriggerAction
{
public enum RotationDirection
{
LeftToRight,
RightToLeft,
TopToBottom,
BottomToTop
}
public class Flip : TriggerAction<FrameworkElement>
{
public static readonly DependencyProperty FrontElementNameProperty =
DependencyProperty.Register("FrontElementName", typeof(string),
typeof(Flip), new PropertyMetadata(null));
[Category("Flip Properties")]
public string FrontElementName { get; set; }
public static readonly DependencyProperty BackElementNameProperty =
DependencyProperty.Register("BackElementName", typeof(string),
typeof(Flip), new PropertyMetadata(null));
[Category("Flip Properties")]
public string BackElementName { get; set; }
public static readonly DependencyProperty DurationProperty =
DependencyProperty.Register("Duration", typeof(Duration),
typeof(Flip), new PropertyMetadata(null));
[Category("Animation Properties")]
public Duration Duration { get; set; }
public static readonly DependencyProperty RotationProperty =
DependencyProperty.Register("Rotation", typeof(RotationDirection),
typeof(Flip), new PropertyMetadata(RotationDirection.LeftToRight));
[Category("Animation Properties")]
public RotationDirection Rotation { get; set; }
private readonly Storyboard _sbF = new Storyboard();
private readonly Storyboard _sbB = new Storyboard();
private bool _forward = true;
protected override void Invoke(object parameter)
{
if (AssociatedObject.Projection == null)
{
FrameworkElement parent = AssociatedObject as FrameworkElement;
UIElement f = null;
UIElement b = null;
if (parent != null)
{
f = parent.FindName(FrontElementName) as UIElement;
if (f != null)
{
PlaneProjection ppFront = new PlaneProjection { CenterOfRotationY = .51 };
f.Projection = ppFront;
f.RenderTransformOrigin = new Point(.5, .5);
}
b = parent.FindName(BackElementName) as UIElement;
if (b != null)
{
PlaneProjection ppBack = new PlaneProjection { CenterOfRotationY = .51, RotationY = 180.0 };
b.Projection = ppBack;
b.RenderTransformOrigin = new Point(.5, .5);
b.Opacity = 0.0;
}
}
PlaneProjection pp = new PlaneProjection { CenterOfRotationY = .51 };
AssociatedObject.RenderTransformOrigin = new Point(.5, .5);
AssociatedObject.Projection = pp;
double to = 180.0;
double from = 0.0;
string property = "RotationY";
switch (Rotation)
{
case RotationDirection.RightToLeft:
to = 0.0;
from = 180.0;
break;
case RotationDirection.TopToBottom:
property = "RotationX";
break;
case RotationDirection.BottomToTop:
to = 0.0;
from = 180.0;
property = "RotationX";
break;
}
_sbF.Duration = Duration;
_sbB.Duration = Duration;
_sbF.Children.Add(CreateDoubleAnimation(pp, property, from, to, true));
_sbB.Children.Add(CreateDoubleAnimation(pp, property, to, from, true));
_sbF.Children.Add(CreateDoubleAnimation(f, "Opacity", 1.0, 0.0, false));
_sbB.Children.Add(CreateDoubleAnimation(f, "Opacity", 0.0, 1.0, false));
_sbF.Children.Add(CreateDoubleAnimation(b, "Opacity", 0.0, 1.0, false));
_sbB.Children.Add(CreateDoubleAnimation(b, "Opacity", 1.0, 0.0, false));
}
if (_forward)
{
_sbF.Begin();
_forward = false;
}
else
{
_sbB.Begin();
_forward = true;
}
}
private static DoubleAnimation CreateDoubleAnimation(DependencyObject element, string property, double from,
double to, bool addEasing)
{
DoubleAnimation da = new DoubleAnimation();
da.To = to;
da.From = from;
if (addEasing)
da.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseOut, Power = 3 };
Storyboard.SetTargetProperty(da, new PropertyPath(property));
Storyboard.SetTarget(da, element);
return da;
}
}
}
相关视频
相关阅读 PPTV与微软达成Silverlight 4 合作Silverlight有什么用?Silverlight是什么微软发布Silverlight3新版MSN2009嵌入Silverlight技术如何用Silverlight Tools实现3D动画如何用Silverlight打造炫目视频listary使用教程 listary的使用技巧
热门文章 没有查询到任何记录。
最新文章
什么是.NET中的TDD?ASP.NET AJAX入门简介
WebMatrix入门教程VC++2008中如何调用GetOpenFileName打开文件PlaySound函数在VC++6.0中如何播放音乐及声请问VC++回调函数怎么用
人气排行 嵌入式实时操作系统VxWorks入门教程ArrayList 与 string、string[] 的转换C#遍历整个文件夹及子目录的文件代码WebMatrix入门教程asp.net判断文件或文件夹是否存在c#判断数据NULL值的方法vc++6.0怎么写Windows简单窗口代码.net解决数据导出excel时的格式问题
查看所有0条评论>>