In my tab SelectionChanged event (is this the correct event, I can't find a tab changed event?), how do I access the new tab?
在我的选项卡选择更改事件(这是正确的事件吗,我找不到选项卡更改事件吗?)中,我如何访问新选项卡?
Also from outside this event in normal code, how do I access the currently selected tab?
同样,在普通代码中,从这个事件之外,我如何访问当前选中的选项卡?
TabControl.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(TabControl_SelectionChanged);
void TabControl_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
//How so access my currently selected tab???
}
3 个解决方案
#1
39
TabControl.SelectedItem is the selected tab.
TabControl。SelectedItem是选中的选项卡。
cast it to a TabItem to get the properties.
将其转换为TabItem以获取属性。
What I mostly do is bind it to a viewmodel.
我主要做的是将它绑定到一个viewmodel。
#2
14
you can use the TabControl.SelectedItem property, it will get you the selected TabItem
您可以使用TabControl。SelectedItem属性,它将获取所选的选项卡项
Sample shown below
示例如下所示
TabItem ti = Tabs1.SelectedItem as TabItem;
MessageBox.Show("This is " + ti.Header + " tab");
#3
6
TabControl.SelectedIndex
gets you the currently selected tab index in version 3.0 and later of the .NET Framework.
TabControl。SelectedIndex在3.0版本和。net框架的稍后版本中为您提供当前选定的选项卡索引。
#1
39
TabControl.SelectedItem is the selected tab.
TabControl。SelectedItem是选中的选项卡。
cast it to a TabItem to get the properties.
将其转换为TabItem以获取属性。
What I mostly do is bind it to a viewmodel.
我主要做的是将它绑定到一个viewmodel。
#2
14
you can use the TabControl.SelectedItem property, it will get you the selected TabItem
您可以使用TabControl。SelectedItem属性,它将获取所选的选项卡项
Sample shown below
示例如下所示
TabItem ti = Tabs1.SelectedItem as TabItem;
MessageBox.Show("This is " + ti.Header + " tab");
#3
6
TabControl.SelectedIndex
gets you the currently selected tab index in version 3.0 and later of the .NET Framework.
TabControl。SelectedIndex在3.0版本和。net框架的稍后版本中为您提供当前选定的选项卡索引。