WPF TabControl 模拟动画

时间:2023-03-09 05:31:50
WPF TabControl 模拟动画
 using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using WangCai.Common; namespace WangCai.Controls
{ public class MyTabControl : TabControl
{ Timer t = null;
private int left = ;
private int AnimationIndex = ;
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
Action a = () =>
{
try
{
AnimationIndex++;
var control = e.Source as MyTabControl;
if (control == null) return;
base.OnSelectionChanged(e);
if (AnimationIndex % == )
{
left = -;
}
else
{
left = ;
} var selectItem = control.SelectedContent as ScrollViewer;
if (selectItem == null)
{ var selectItem_2 = control.SelectedContent as Grid;
if (selectItem_2 == null)
{
var selectItem_3 = control.SelectedContent as StackPanel;
if (selectItem_3 == null) return;
selectItem_3.Visibility = Visibility.Collapsed;
t = new Timer(Move, selectItem_3, , );
return;
}
selectItem_2.Visibility = Visibility.Collapsed;
t = new Timer(Move, selectItem_2, , );
return;
}
selectItem.Visibility = Visibility.Collapsed; t = new Timer(Move, selectItem, , ); }
catch (Exception)
{ }
};
this.Dispatcher.BeginInvoke(a);
} public void Move(object o)
{ Action a = () =>
{
try
{
if (AnimationIndex % == )
{
left +=;
if (left > )
{
t.Dispose(); return;
}
AnimationIndex = ;
}
else
{ left -= ; if (left <= )
{
t.Dispose(); return;
}
AnimationIndex = ;
} var selectItem = o as ScrollViewer;
if (selectItem == null)
{
var selectItem_2 = o as Grid;
if (selectItem_2 == null)
{
var selectItem_3 = o as StackPanel;
if (selectItem_3 == null) return;
selectItem_3.Visibility = Visibility.Visible;
selectItem_3.Margin = new Thickness(left, , , ); return;
}
selectItem_2.Visibility = Visibility.Visible;
selectItem_2.Margin = new Thickness(left, , , );
return;
}
selectItem.Visibility = Visibility.Visible;
selectItem.Margin = new Thickness(left, , , );
}
catch (Exception)
{ } };
this.Dispatcher.BeginInvoke(a);
} }
}