栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C# > C#教程

WPF实现3D翻牌式倒计时特效

C#教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

WPF实现3D翻牌式倒计时特效

本文实例为大家分享了WPF实现3D翻牌式倒计时的具体代码,供大家参考,具体内容如下

实现效果如下:

思路:使用自定义控件,设置一个背板 MyCardControlBottom,一个卡牌翻动的前部 MyCardControlFront,一个卡牌翻动后的背部 MyCardControlBack,另外实现卡牌翻动的MyCardControl;在主窗体中设置一计时器,根据卡牌上的数字和计时器时间启动翻牌动作。

主要代码:

1、自定义控件MyCardControlBottom


 
  
   
  
  
   
    
    
   
  
  
   
    
    
   
   
    
     
    
   
   
    
     
    
   
  
 

其中BottomText为自定义属性。

public static readonly DependencyProperty BottomTextProperty = DependencyProperty.Register("BottomText", typeof(string), typeof(MyCardControlBottom), new Propertymetadata(null));
  public string BottomText
  {
   get { return (string)GetValue(BottomTextProperty); }
   set { SetValue(BottomTextProperty, value); }
  }

2、自定义控件MyCardControlFront


 
  
   
    
    
   
  
  
   
    
   
  
 

其中FrontText为自定义属性。

3、自定义控件MyCardControlBack

窗体大部分布局与MyCardControlFront 相同,字体部分需要进行翻转显示,其中BackText为自定义属性。


   
    
   
   
    
   

4、自定义控件MyCardControl

卡牌翻转动作在这里实现。


 
  
   
  
  
   
    
     
    
   
   
    
     
      
     
     
      
     
     
      
     
    
    
     
      
     
     
      
     
     
      
     
    
    
     
      

 

      
     
    
   
  
 

加载时赋值:

public int ShowValue { get; set; }  
  
  private void MyUserControl_Loaded(object sender, RoutedEventArgs e)
  {
   this.frontControl.FrontText = ShowValue.ToString();
  }

5、主窗体交互逻辑

private int Count = 10;
private DispatcherTimer frameTimer;
private int Timevalue = 0;
 
  private void Window_Loaded(object sender, RoutedEventArgs e)
  {
   this.bottomControl.BottomText = Count.ToString();
 
   for (int i = 1; i <= Count; i++)
   {
    var card = new MyCardControl();
    card.ShowValue = i;
    this.mainGrid.Children.Add(card);
    Canvas.SetZIndex(card, i);
   }
 
   frameTimer = new DispatcherTimer();
   frameTimer.Tick += Onframe;
   frameTimer.Interval = TimeSpan.FromSeconds(1);
   frameTimer.Start();
  }
 
  private void onframe(object sender, EventArgs e)
  {
   if (Timevalue >= Count)
   {
    if (frameTimer != null)
     frameTimer.Stop();
    return;
   }
 
   if(Timevalue == Count - 1)
   {
    this.bottomControl.BottomText = 0.ToString();
   }
 
   List cardList = GetChildObjects(this.mainGrid);
   foreach (var item in cardList)
   {
    if(item.ShowValue == Count - Timevalue)
    {
     Canvas.SetZIndex(item, Count + Timevalue);
 
     DoubleAnimation da = new DoubleAnimation();
     da.Duration = new Duration(TimeSpan.FromSeconds(1));
     da.To = 180d;
     item.ShowValue--;
     item.backControl.BackText = item.ShowValue.ToString();
     
     AxisAngleRotation3D aar = item.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D;
     if (aar != null)
      aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
     
     break;
    }
   }
 
   Timevalue++;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/121801.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号