简体   繁体   English

如何有条件地完全隐藏TabControl的TabPanel部分?

[英]How can I conditionally hide the TabPanel portion of a TabControl in its entirety?

I've found a lot of variations of this question, but the conversation always seems to revolve around the individual TabItems , and not the TabPanel as a thing unto itself. 我发现这个问题有很多变体,但是对话似乎总是围绕着单个TabItems ,而不是围绕TabPanel本身展开。

My main window has a TabControl on it. 我的主窗口上有一个TabControl The tabs are views. 这些选项卡是视图。 One of those views is special...a navigation display, whereas all of the others are the "sections" that the nav view can open. 这些视图之一是特殊的……导航显示,而其他所有视图都是导航视图可以打开的“部分”。

What I am trying to accomplish is that when the user is viewing the nav view, the tabs all go away. 我要完成的工作是,当用户查看导航视图时,所有选项卡都消失了。 Ie hide the whole TabPanel instead of having to hide each TabItem one-by-one. 即隐藏整个TabPanel而不必一次一个地隐藏每个TabItem While viewing any other page, the tabs show, for easy movement between views. 在查看任何其他页面时,将显示选项卡,以便在视图之间轻松移动。

I created this question in response to a suggestion made on my other question . 我根据另一个问题的建议创建了这个问题

The problem I have is that the TabPanel does not seem to have a Template that I can override in order to do something like a DataTrigger bound to the Visibility property. 我遇到的问题是, TabPanel似乎没有要进行绑定到Visibility属性的DataTrigger类的Template ,可以重写该Template The closest I have gotten is a plain old Style.Setter . 我得到的最接近的是一个普通的老式Style.Setter

Any suggestions on how to get what I am after? 关于如何获得我所追求的任何建议?

You basically provided the answer yourself - the right combination is to use a Style together with a DataTrigger . 您基本上可以自己提供答案-正确的组合是将StyleDataTrigger一起使用。 The trick is to define a Style with TargetType set to {x:Type TabPanel} , and put it as a resource of the TabControl - that way the style will be applied to the TabPanel (because it's an implicit style ). 诀窍是定义一个TargetType设置为{x:Type TabPanel}Style ,并将其作为TabControl的资源-这样,该样式将应用于TabPanel (因为这是隐式样式 )。 Here's an example: 这是一个例子:

<TabControl (...)>
    <TabControl.Resources>
        <Style TargetType="{x:Type TabPanel}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding SelectedIndex, RelativeSource={RelativeSource AncestorType=TabControl}}"
                             Value="0">
                    <Setter Property="Visibility" Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TabControl.Resources>
    (...)
</TabControl>

In this example the panel will be collapsed while the first item is selected. 在此示例中,选择第一项时面板将折叠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM