带有新选项卡按钮的 TabControl
我有以下 TabControl:
<TabControl x:Name="Networks">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DisplayName}" />
<Button Content="X" cal:Message.Attach="CloseItem($dataContext)" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
如您所见,它使用 Caliburn.Micro 绑定到 ViewModel,但我认为这是不相关的。 如何在右侧的该控件上添加一个按钮以添加新的 TabItem?我正在寻找简单的解决方案。我已经搜索过这个,但我还没有找到一个简单的实现。
谢谢
I have the following TabControl:
<TabControl x:Name="Networks">
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DisplayName}" />
<Button Content="X" cal:Message.Attach="CloseItem($dataContext)" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
As you can see it is bound to a ViewModel using Caliburn.Micro, but I think this is unrelevant.
How would I add a button on to this control on the right side to add new TabItems? I'm looking for simple solution. I've searched for this but I haven't found an easy implementation of this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
ItemsSource
设为CompositeCollection
带有CollectionContainer
用于开头的选项卡,末尾有一个显式的TabItem
,可以在单击时添加新项目(一个+
-tab(如某些浏览器中那样)。You could make the
ItemsSource
aCompositeCollection
with aCollectionContainer
for the tabs at the beginning and one explicitTabItem
at the end which can add a new item on click (a+
-tab as in some browsers).