CloseableTabs 的自定义 TabControl
这里有一些可关闭选项卡的解决方案,但它们都依赖于集合的所有者来提供关闭功能。
我认为也许可以通过创建自定义 TabControl
和 TabItem
这可以在 CodeBehind 中完成。
这个想法是以某种方式提醒来自 TabItem
的 TabControl
关闭按钮已被按下(可能通过冒泡事件或其他事件,请建议),然后删除该特定的来自 ItemsSource
的 TabItem
中包含的项目。
问题是我不确定这如何或是否可能。您能否以某种方式从 TabControl
中设置为 ItemsSource
的集合中删除项目?我们是否可以设置一个新的 DP 母猪,让我们可以完全控制集合,并将其设置为代码隐藏中的 ItemsSource
。
任何人都这样做过或有任何想法如何做到这一点。这有可能吗?
There are a few solutions here for Closeable tabs but they all depend on the owner of the collection to provide the closing functionality.
I thought perhaps it would be possible by creating a Custom TabControl
and TabItem
that this could be done in the CodeBehind.
The idea would be to somehow alert the TabControl
from the TabItem
that the close button has been pressed (perhaps with a bubbling event or something, please suggest) and then remove that particular items wrapped in that TabItem
from the ItemsSource
.
Problem is I'm not sure how or even if this is possible. Can you somehow remove items from a collection set as ItemsSource
in a TabControl
? Could we perhaps set a new DP sow we have full control over the Collection and just set that as ItemsSource
in Code Behind.
Anyone done this or has any ideas hwo to do this. Is it even possible at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使这在技术上是可行的,我还是建议坚持使用 MV-VM。让集合的所有者(即 ViewModel)控制从集合中添加/删除项目。
让视图变得精简并通过数据绑定与虚拟机的集合同步。这可以防止视图变得复杂,并消除阻碍可测试性的 GUI。
您应该发现这是 WPF 阻力最小的路径。
Even if that's technically possible, I'd advise sticking to M-V-VM. Let the owner of the collection i.e. the ViewModel control adding/deleting items from the collection.
Let the View be thin and sync with the VM's collection via data-binding. This keeps the Views from getting complex and eliminates the GUI which is a deterrent to testability.
You should find that as the path of least WPF resistance.
这个问题出现在我们的应用程序中,所以我想我应该发布我的解决方案。 ClosableTabControl 通过从绑定的 ItemsSource 中删除项目来关闭任何选项卡。这是从其他解决方案中部分删除的(Szymon Kobalczyk等人.)。
ClosableTabControl.cs:
ClosableTabItem.cs:
Themes/Generic.xaml:
This came up in our application, so I figured I would post my solution. ClosableTabControl closes any tab by removing the item from the bound ItemsSource. This is partially scraped from other solutions (Szymon Kobalczyk et al.).
ClosableTabControl.cs:
ClosableTabItem.cs:
Themes/Generic.xaml: