在 TabItem 中获取自定义内容可见时出现问题

发布于 2024-09-08 10:00:57 字数 1052 浏览 1 评论 0原文

我有一个自定义 ItemsControl (WorKArea),它将所有项目标记到 WorkSheet 实例中。

我有一个 ItemsControl 的样式,它使用 TabControl 来显示内容。每张工作表都会创建一个选项卡。风格是:

<Style TargetType="{x:Type local:WorkArea}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:WorkArea}">
                <TabControl ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:WorkArea}}, Path=Items}">
                    <TabControl.ItemContainerStyle>
                        <Style TargetType="TabItem">
                            <Setter Property="Header" Value="{Binding Title}" />
                        </Style>
                    </TabControl.ItemContainerStyle>
                </TabControl>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

到目前为止还不错。 “工作表”出现,并且标题已正确绑定到页眉。

我怎样才能让标签现在显示内容?无论我尝试什么,每个工作表都没有显示任何内容 - 内容始终为空。有人有正确的代码吗?

I have a custom ItemsControl (WorKArea) that marks all items it has into a WorkSheet instance.

I have a style for the ItemsControl that uses a TabControl to show the content. Every sheet creates a tab. The style is:

<Style TargetType="{x:Type local:WorkArea}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:WorkArea}">
                <TabControl ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:WorkArea}}, Path=Items}">
                    <TabControl.ItemContainerStyle>
                        <Style TargetType="TabItem">
                            <Setter Property="Header" Value="{Binding Title}" />
                        </Style>
                    </TabControl.ItemContainerStyle>
                </TabControl>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

So far so good. The "sheets" show up, and the title is properly bound to the Header.

How can I get the tabs showing the content now? Whatever I try, nothing shows up at all for every WorkSheet - the content is always empty. Anyone the proper code?

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

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

发布评论

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

评论(1

意中人 2024-09-15 10:00:57

您的工作区域应提供一个 ContentTemplate 属性,并且 TabControl 应具有一个 TemplateBinding 属性。

Your work area should provide a ContentTemplate property and the TabControl should have a TemplateBinding which to it.

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