WPF TabControl 模拟动画


  1 using System;
  2 using System.Threading;
  3 using System.Windows;
  4 using System.Windows.Controls;
  5 using WangCai.Common;
  6 
  7 namespace WangCai.Controls
  8 {
  9 
 10     public class MyTabControl : TabControl
 11     {
 12 
 13         Timer t = null;
 14         private int left = 0;
 15         private int AnimationIndex = 1;
 16         protected override void OnSelectionChanged(SelectionChangedEventArgs e)
 17         {
 18             Action a = () =>
 19             {
 20                 try
 21                 {
 22                     AnimationIndex++;
 23                     var control = e.Source as MyTabControl;
 24                     if (control == null) return;
 25                     base.OnSelectionChanged(e);
 26                     if (AnimationIndex % 2 == 0)
 27                     {
 28                         left = -100;
 29                     }
 30                     else
 31                     {
 32                         left = 100;
 33                     }
 34 
 35                     var selectItem = control.SelectedContent as ScrollViewer;
 36                     if (selectItem == null)
 37                     {
 38 
 39                         var selectItem_2 = control.SelectedContent as Grid;
 40                         if (selectItem_2 == null)
 41                         {
 42                             var selectItem_3 = control.SelectedContent as StackPanel;
 43                             if (selectItem_3 == null) return;
 44                             selectItem_3.Visibility = Visibility.Collapsed;
 45                             t = new Timer(Move, selectItem_3, 0, 5);
 46                             return;
 47                         }
 48                         selectItem_2.Visibility = Visibility.Collapsed;
 49                         t = new Timer(Move, selectItem_2, 0, 5);
 50                         return;
 51                     }
 52                     selectItem.Visibility = Visibility.Collapsed;
 53 
 54                     t = new Timer(Move, selectItem, 0, 2);
 55 
 56                 }
 57                 catch (Exception)
 58                 {
 59 
 60                 }
 61             };
 62             this.Dispatcher.BeginInvoke(a);
 63         }
 64 
 65 
 66         public void Move(object o)
 67         {
 68 
 69             Action a = () =>
 70             {
 71                 try
 72                 {
 73                     if (AnimationIndex % 2 == 0)
 74                     {
 75                         left +=6;
 76                         if (left > 5)
 77                         {
 78                             t.Dispose();
 79 
 80                             return;
 81                         }
 82                         AnimationIndex = 0;
 83                     }
 84                     else
 85                     {
 86 
 87                         left -= 6;
 88 
 89                         if (left <= 0)
 90                         {
 91                             t.Dispose();
 92 
 93                             return;
 94                         }
 95                         AnimationIndex = 1;
 96                     }
 97 
 98                     var selectItem = o as ScrollViewer;
 99                     if (selectItem == null)
100                     {
101                         var selectItem_2 = o as Grid;
102                         if (selectItem_2 == null)
103                         {
104                             var selectItem_3 = o as StackPanel;
105                             if (selectItem_3 == null) return;
106                             selectItem_3.Visibility = Visibility.Visible;
107                             selectItem_3.Margin = new Thickness(left, 0, 0, 0);
108 
109                             return;
110                         }
111                         selectItem_2.Visibility = Visibility.Visible;
112                         selectItem_2.Margin = new Thickness(left, 0, 0, 0);
113                         return;
114                     }
115                     selectItem.Visibility = Visibility.Visible;
116                     selectItem.Margin = new Thickness(left, 0, 0, 0);
117                 }
118                 catch (Exception)
119                 {
120 
121                 }
122 
123             };
124             this.Dispatcher.BeginInvoke(a);
125         }
126 
127 
128     }
129 }

优质内容筛选与推荐>>
1、java线程系列---synchronized详解
2、java线程系列---类中的定时器Timer
3、Spring Java配置
4、php 5.3新增的闭包语法介绍function() use() {}
5、年末跳槽


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号