今天,给大家分享我刚做好的可旋转的三维界面效果,不打算过多介绍,可以看看下面几个图片。
其实,如果把这个程序的窗口变成透明,就可以做出QQ 2013的登陆界面动画效果了。
把这个例子运行后,通过键盘上的左,右箭键来控制旋转的方向。
这里的快捷键,我使用了KeyBinding类来设置,另外,自定义了两个命令,分别执行向左转和向右转的动画。
/// <summary>
/// 向前移动
/// </summary>
public class ForwCommand : ICommand
{
public bool CanExecute(object parameter)
{
if (parameter == null)
{
return false;
}
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
AxisAngleRotation3D rot = parameter as AxisAngleRotation3D;
DoubleAnimation d = new DoubleAnimation();
d.Duration = new Duration(TimeSpan.FromMilliseconds(800));
d.By = 90d;
rot.BeginAnimation(AxisAngleRotation3D.AngleProperty, d, HandoffBehavior.Compose);
}
}
/// <summary>
/// 向后移动
/// </summary>
public class BackCommand : ICommand
{
public bool CanExecute(object parameter)
{
if (parameter == null)
{
return false;
}
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
AxisAngleRotation3D rot = parameter as AxisAngleRotation3D;
DoubleAnimation d = new DoubleAnimation();
d.By = -90d;
d.Duration = new Duration(TimeSpan.FromMilliseconds(800));
rot.BeginAnimation(AxisAngleRotation3D.AngleProperty, d, HandoffBehavior.Compose);
}
}
然后将其应用到主窗口类中。
// 设置快捷键
KeyBinding forwBind = new System.Windows.Input.KeyBinding();
forwBind.Command = new ForwCommand();
forwBind.CommandParameter = ar;
forwBind.Key = System.Windows.Input.Key.Right;
this.InputBindings.Add(forwBind);
KeyBinding backBind = new System.Windows.Input.KeyBinding();
backBind.Command = new BackCommand();
backBind.CommandParameter = ar;
backBind.Key = System.Windows.Input.Key.Left;
this.InputBindings.Add(backBind);
至于UI,就参考源代码中的XAML,主要用到了三维材料。
稍后我把源代码上传到资源区。