ItemTemplate - 工作错误。自定义外观和绑定

发布于 2024-12-28 07:31:31 字数 700 浏览 1 评论 0原文

我创建了自己的 ExtendedTabControl 来完全改变它的外观。工作正常。我还创建了 CloseableTabItem 控件。它也有效。但是...到目前为止,我已经通过这种方式手动将 CloseableTabItem 放入我的 ExtendedTabControl 中:

<etc:ExtendedTabControl>            
    <etc:CloseableTabItem Header="First Item">
        <...some  content... />
    </etc:CloseableTabItem>            
</etc:ExtendedTabControl> 

现在我想将 ObservableCollection 绑定到我的 ExtendedTabControl。 Collection 内的对象包含: header 和 contentText。我设置了 ItemSource,好的,有效。但是我怎样才能使 TabItems 成为我的 CloseableTabItems 呢?更重要的是,如何将我的类对象绑定到 CloseableTabItems?我注意到 TabControl 有一个名为 ItemTemplate 的属性,但设置它并不会完全改变它的外观。还有一个我无法改变的背景。因此,外观有效,但绑定不起作用,或者绑定有效,但外观仅部分有效。我能做些什么?请帮忙。

I have created my own ExtendedTabControl to totally change it's apperance. It works ok. I have also created CloseableTabItem control. It works as well. However... so far I have manually put CloseableTabItem in my ExtendedTabControl this way:

<etc:ExtendedTabControl>            
    <etc:CloseableTabItem Header="First Item">
        <...some  content... />
    </etc:CloseableTabItem>            
</etc:ExtendedTabControl> 

Now I want to bind ObservableCollection to my ExtendedTabControl. Objects inside the Collection contains: header and contentText. I set ItemSource, ok, works. But how can I make the TabItems be my CloseableTabItems? What is more, how to bind my class objects to that CloseableTabItems? I Have noticed TabControl has a property called ItemTemplate, but setting it does not change it's apperance totally. There is still a background which I can't change. So an apperance works, but binding does not or the bindings work, but the apperance only partly. What can I do? Please help.

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

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

发布评论

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

评论(1

唐婉 2025-01-04 07:31:31

在您的 ExtendedTabControl 代码中,您需要将为项目生成的项目容器更改为您的 ClosableTabItem :(

public class ExtendedTabControl : TabControl
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new CloseableTabItem();
    }
}

有一个相关的方法,IsItemItsOwnContainerOverride,您可能还想覆盖它)

TabControls 有两个可以设置的模板,ContentTemplate 用于模板项目内容区域,以及 ItemTemplate 应该模板化标题。

要修改生成的选项卡上的其他属性,请使用 < code>ItemContainerStyle,现在的 TargetTypeClosableTabItem

In your ExtendedTabControl code you need to change the item container which is generated for items to your ClosableTabItem:

public class ExtendedTabControl : TabControl
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new CloseableTabItem();
    }
}

(There is a related method, IsItemItsOwnContainerOverride, which you might also want to override)

TabControls have two template you can set, the ContentTemplate which templates the item content area, and the ItemTemplate which should template the header.

To modify other properties on the generated tabs use the ItemContainerStyle, which now has a TargetType of ClosableTabItem.

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