C# 在选项卡';s PreviewMouseDown事件
我有一个WPF选项卡控件,它有两个选项卡(a,B)。由于选项卡Item上没有单击的C# 在选项卡';s PreviewMouseDown事件,c#,wpf,messagebox,C#,Wpf,Messagebox,我有一个WPF选项卡控件,它有两个选项卡(a,B)。由于选项卡Item上没有单击的事件,因此我在选项卡B上添加了一个previewMouseDown事件,将显示一个messageBox。但是,在我关闭messageBox之后,我的应用程序将不会导航到选项卡B。有人可以帮助我吗 C#代码片段: private void MyTabB_PreviewMouseDown(object sender, MouseButtonEventArgs e) { MessageBox.
事件,因此我在选项卡B上添加了一个previewMouseDown
事件,将显示一个messageBox
。但是,在我关闭messageBox之后,我的应用程序将不会导航到选项卡B。有人可以帮助我吗
C#代码片段:
private void MyTabB_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Please login");
}
您可以使用选项卡ControlSelectionChanged事件
因为您知道登录的所选选项卡,比如索引0,所以在MessageBox之后更改所选选项卡
MyTabB_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
TabControl tc= ((TabControl)sender;
if(tc.SelectedIndex == tc.Items.IndexOf(A/*Login tab*/))
{
MessageBox.Show("Login")
tc.SelectedIndex = tc.Items.IndexOf(B);
}
}
这意味着,每当您选择一个you will消息框时,就会弹出,然后您就可以登录了
或者,为什么不将带有ClickedEvent的按钮或任何控件放在a中,然后当单击时tc.SelectedIndex会发生更改