如何有条件地完全隐藏 TabControl 的 TabPanel 部分? [英] How can I conditionally hide the TabPanel portion of a TabControl in its entirety?

查看:45
本文介绍了如何有条件地完全隐藏 TabControl 的 TabPanel 部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个问题有很多变体,但对话似乎总是围绕着个别的 TabItems 而不是 TabPanel 本身.

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.

我的主窗口上有一个 TabControl.选项卡是视图.其中一个视图是特殊的……导航显示,而所有其他视图都是导航视图可以打开的部分".

My main window has a TabControl on it. 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.

我想要完成的是,当用户查看导航视图时,所有选项卡都消失了.IE.隐藏整个 TabPanel 而不是必须一个一个地隐藏每个 TabItem.在查看任何其他页面时,标签会显示,以便在视图之间轻松移动.

What I am trying to accomplish is that when the user is viewing the nav view, the tabs all go away. I.e. hide the whole TabPanel instead of having to hide each TabItem one-by-one. 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.

我遇到的问题是 TabPanel 似乎没有我可以覆盖的 Template 以执行类似 DataTrigger 绑定到 Visibility 属性.我得到的最接近的是一个普通的 Style.Setter.

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. The closest I have gotten is a plain old Style.Setter.

关于如何获得我所追求的东西有什么建议吗?

Any suggestions on how to get what I am after?

推荐答案

您基本上自己提供了答案 - 正确的组合是将 StyleDataTrigger 一起使用.诀窍是定义一个 Style,其中 TargetType 设置为 {x:Type TabPanel},并将其作为 的资源TabControl - 这样样式就会应用到 TabPanel(因为它是一个 隐式样式).举个例子:

You basically provided the answer yourself - the right combination is to use a Style together with a DataTrigger. 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). 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.

这篇关于如何有条件地完全隐藏 TabControl 的 TabPanel 部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆