wpf 窗体加载于tabControl_SelectionChanged时间触发顺序
我有一个窗体 里面有一个tabControl控件。并写了tabControl_SelectionChanged事件。
代码如下:
/// <summary>
/// 选择选项卡
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public event RoutedEventHandler tabChanged;
private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.Source is TabControl)
{
int tab = this.tabControl1.SelectedIndex;
TabIniti(tab);
}
}
public void TabIniti(int tab)
{
switch (tab)
{
case 0:
this.cbbm.Visibility = Visibility.Collapsed;
this.sjxx.Visibility = Visibility.Collapsed;
this.xxxx.Visibility = Visibility.Visible;
break;
case 1:
this.cbbm.Visibility = Visibility.Visible;
this.sjxx.Visibility = Visibility.Collapsed;
this.xxxx.Visibility = Visibility.Collapsed;
break;
case 2:
this.cbbm.Visibility = Visibility.Collapsed;
this.sjxx.Visibility = Visibility.Visible;
this.xxxx.Visibility = Visibility.Collapsed;
break;
}
}
InitializeComponent();
tabControl.SelectionChanged += firstTabControl_SelectionChanged;
private void firstTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
tabControl.SelectionChanged -= firstTabControl_SelectionChanged;
tabControl.SelectedIndex = -1;
tabControl.SelectionChanged += tabControl_SelectionChanged;
}
private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//你本来的代码......
}