ItemTemplate - 工作错误。自定义外观和绑定
我创建了自己的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 ExtendedTabControl 代码中,您需要将为项目生成的项目容器更改为您的 ClosableTabItem :(
有一个相关的方法,
IsItemItsOwnContainerOverride
,您可能还想覆盖它)TabControls
有两个可以设置的模板,ContentTemplate
用于模板项目内容区域,以及ItemTemplate
应该模板化标题。要修改生成的选项卡上的其他属性,请使用 < code>ItemContainerStyle,现在的
TargetType
为ClosableTabItem
。In your
ExtendedTabControl
code you need to change the item container which is generated for items to yourClosableTabItem
:(There is a related method,
IsItemItsOwnContainerOverride
, which you might also want to override)TabControls
have two template you can set, theContentTemplate
which templates the item content area, and theItemTemplate
which should template the header.To modify other properties on the generated tabs use the
ItemContainerStyle
, which now has aTargetType
ofClosableTabItem
.