0

我在我的窗口中添加了一些控件和选项卡控件。现在我想在用户按下tabItem2时隐藏控件,就像我需要的每个tabItem应该显示一些控件并且应该隐藏一些控件如何进行这种类型的功能?

4

2 回答 2

2

只需在 TabControl 中声明控件

<TabControl>
    <TabItem>
        <Button x:Name="Button1"/>
    </TabItem>
    <TabItem>
        <Button/>
    </TabItem>
</TabControl>

或者,您可以通过处理 TabControl 的 SelectionChanged 事件来隐藏所需的控件。

void OnTabControlSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    Button1.Visibility = Visibility.Collapsed;
}
于 2012-11-18T18:14:57.833 回答
0

For Clarification: do you mean that for each tabitem you press, you would like a different set of tabitems to be visible? If so, I'd suggest wrapping that functionality up in a UserControl, and providing the "set" logic as part of the codebehind for that control.

于 2012-11-18T19:08:32.650 回答