C# WPF:通过单击按钮更改当前选项卡?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14185814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:55:33 来源:igfitidea点击:
C# WPF: Changing current tab with button click?
提问by Georg Trakl
I would like to have a button on tab1. When that button is clicked I would like to be taken to tab2. How do I make this happen?
我想在 tab1 上有一个按钮。单击该按钮后,我想进入 tab2。我该如何做到这一点?
回答by kmatyaszek
You can use SelectedIndexproperty.
您可以使用SelectedIndex财产。
Example:
例子:
<TabControl x:Name="myTabControl">
<TabControl.Items>
<TabItem Header="Tab1">
<StackPanel>
<TextBlock Text="Tab1 Content" />
<Button Content="Go to Tab2" Margin="5"
HorizontalAlignment="Center"
Click="Button_Click"/>
</StackPanel>
</TabItem>
<TabItem Header="Tab2">
<TextBlock Text="Tab2 Content" />
</TabItem>
</TabControl.Items>
</TabControl>
Code-behind:
代码隐藏:
private void Button_Click(object sender, RoutedEventArgs e)
{
myTabControl.SelectedIndex = 1;
}

