WPF:触发检查 TabControl 是否只有 1 个选项卡!

发布于 2024-09-08 18:34:53 字数 160 浏览 6 评论 0原文

我可以创建任何触发器来查看 Tabcontrol 是否只有一个 TabItem。在这些情况下,我实际上在代码隐藏中有一个 TabItem 集合,我可以在其中使用 count 方法。

如果只有一个选项卡,我不想隐藏 TabPanel。我可以直接调用visibility=collapse 吗?

Is there any trigger I can create to see if a Tabcontrol has only one TabItem. In these cases I actually have a TabItem collection in the codebehind wich I could possibly use a count method on.

In the case of only one tab I wan't to hide the TabPanel. Can I just call visibility=collapse on it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅哥哥的热头脑 2024-09-15 18:34:53

在 TabItems 的控件模板中,我放置了:

<ControlTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl, AncestorLevel=1}}" Value="1">
             <Setter Property="Visibility" Value="Collapsed" />
        </DataTrigger>
</ControlTemplate.Triggers>

它的工作原理就像一个魅力。

In the control template of the TabItems I put:

<ControlTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=Items.Count, RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl, AncestorLevel=1}}" Value="1">
             <Setter Property="Visibility" Value="Collapsed" />
        </DataTrigger>
</ControlTemplate.Triggers>

and it works like a charm.

2024-09-15 18:34:53

如果您在后面的代码中使用 ObservableCollection,则可以使用 CollectionChanged 事件,然后检查集合的大小。
关于TabPanel的可见性我不知道,但你可以尝试一下。

If you are using an ObservableCollection in the code behind, you could use the CollectionChanged event, and check the size of the collection then.
About the TabPanel's visibility I don't know but you can try it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文