private int currentTabIndex = 0;
private DispatcherTimer dispatcherTimer;
private void StartSwitchTabs()
{
dispatcherTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(5),
};
dispatcherTimer.Tick += (sender, e) =>
{
// 切换TabItem
TabControl1.SelectedIndex = currentTabIndex;
currentTabIndex++;
if (currentTabIndex >= TabControl1.Items.Count)
{
currentTabIndex = 0; // 循环切换到第一个TabItem
dispatcherTimer.Stop();
}
};
dispatcherTimer.Start();
}
WPF的TabControl通过Timer后台切换Item
于 2023-12-21 14:15:47 首次发布