如何获取嵌套在 TabControl 的 TabItem 中的所有控件/UI 元素?
我尝试了一切但都未能获得它们。
(设置 SelectedTab):
现在我需要类似这样的东西:
在Silvermind之后: 这样做,Count始终为1:
我尝试了一切但都未能获得它们。
(设置 SelectedTab):
private TabItem SelectedTab = null;
private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectedTab = (TabItem)tabControl1.SelectedItem;
}
现在我需要类似这样的东西:
private StackPanel theStackPanelInWhichLabelsShouldBeLoaded = null;
foreach (Control control in tabControl.Children /*doesnt exist*/, or tabControl.Items /*only TabItems*/, or /*SelectedTab.Items ??*/ ) //I Have no plan
{
if(control is StackPanel)
{
theStackPanelInWhichLabelsShouldBeLoaded = control;
//Load Labels in the Stackpanel, thats works without problems
}
}
在Silvermind之后: 这样做,Count始终为1:
UpdateLayout();
int nChildCount = VisualTreeHelper.GetChildrenCount(SelectedTab);