WPF TabControl 更改选定的选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1479392/
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-08 21:01:59  来源:igfitidea点击:

WPF TabControl Change selected tab

wpftabcontrolselecteditem

提问by Kent Boogaart

Hi I have two questions.

你好,我有两个问题。

  1. How do I programatically change the selected tab in a WPF Tab control from one tab to another.
  2. How would I get a reference to this "other tab" in which I want to set the selected tab?
  1. 如何以编程方式将 WPF Tab 控件中选定的选项卡从一个选项卡更改为另一个选项卡。
  2. 我如何获得对要在其中设置所选选项卡的“其他选项卡”的引用?

回答by Kent Boogaart

  1. Use SelectedIndexor SelectedItemor by changing the value of the property to which those properties are bound
  2. If you're using SelectedIndex, you don't need a reference to the tab. If you're using SelectedItem, you need a reference to the data itemfor that tab - not the tab itself. If you've bound one of those properties to another property, you change that property rather than changing the property on the TabControl.
  1. 使用SelectedIndexSelectedItem或 通过更改绑定这些属性的属性的值
  2. 如果您正在使用SelectedIndex,则不需要对选项卡的引用。如果您使用的是SelectedItem,则需要对该选项卡的数据项的引用- 而不是选项卡本身。如果您已将这些属性之一绑定到另一个属性,则更改该属性而不是更改TabControl.