带有新选项卡按钮的 TabControl

发布于 2024-12-24 02:30:30 字数 578 浏览 6 评论 0原文

我有以下 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 技术交流群。

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

发布评论

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

评论(1

贩梦商人 2024-12-31 02:30:30

您可以将 ItemsSource 设为 CompositeCollection 带有 CollectionContainer 用于开头的选项卡,末尾有一个显式的 TabItem,可以在单击时添加新项目(一个 +-tab(如某些浏览器中那样)。

You could make the ItemsSource a CompositeCollection with a CollectionContainer for the tabs at the beginning and one explicit TabItem at the end which can add a new item on click (a +-tab as in some browsers).

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