1 public class MyTabControl : TabControl 2 { 3 4 Timer t = null; 5 protected override void OnSelectionChanged(SelectionChangedEventArgs e) 6 { 7 Action a = () => 8 { 9 try 10 { 11 var control = e.Source as MyTabControl; 12 if (control == null) return; 13 base.OnSelectionChanged(e); 14 left = 80; 15 var selectItem = control.SelectedContent as Grid; 16 17 selectItem.Visibility = Visibility.Collapsed; 18 19 t = new Timer(Move, selectItem, 0, 2); 20 } 21 catch (Exception) 22 { 23 24 MainPanelWindow.TimerManager(true); 25 } 26 }; 27 this.Dispatcher.BeginInvoke(a); 28 } 29 30 private int left = 80; 31 public void Move(object o) 32 { 33 34 Action a = () => 35 { 36 try 37 { 38 left -= 6; 39 if (left <= 0) 40 { 41 t.Dispose(); 42 43 return; 44 } 45 46 47 var selectItem = o as Grid; 48 if (selectItem == null) return; 49 50 selectItem.Visibility = Visibility.Visible; 51 selectItem.Margin = new Thickness(left, 0, 0, 0); 52 } 53 catch (Exception) 54 { 55 56 } 57 }; 58 this.Dispatcher.BeginInvoke(a); 59 } 60 61 }
WPF TabControl 模拟动画,布布扣,bubuko.com
原文:http://www.cnblogs.com/gaobing/p/3830275.html