文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页技术开发.Net 专栏 → silverlight例子 翻转切换效果

silverlight例子 翻转切换效果

时间:2010/2/3 11:23:00来源:本站整理作者:我要评论(0)

翻转切换效果。
完整代码如下: 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时的格式问题