使用 WPF 关闭嵌套选项卡?
我正在尝试设计一个包含嵌套选项卡的 UI,但我似乎找不到有关如何以 MVVM 方式删除嵌套选项卡的信息。
这是我的 XAML(为了简洁而进行了剪裁):
<TabControl Name="ProjectTabControl" DockPanel.Dock="Top" ItemsSource="{Binding ProjectTabs}" IsSynchronizedWithCurrentItem="True">
<TabControl.ContentTemplate>
<DataTemplate>
<TabControl DockPanel.Dock="Top" ItemsSource="{Binding FileTabs}" Padding="1">
<Button Command="{Binding CloseTabCommand}" CommandParameter="TabItem" />
</TabControl>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
我的问题是:我应该在 CommandParameter 中传递什么参数?以及如何在 ViewModel 中影响它以正确删除选项卡?
I'm trying to design a UI that contains nested tabs, but I can't seem to find information on how to remove the nested tabs in an MVVM fashion.
Here's my XAML (snipped for brevity):
<TabControl Name="ProjectTabControl" DockPanel.Dock="Top" ItemsSource="{Binding ProjectTabs}" IsSynchronizedWithCurrentItem="True">
<TabControl.ContentTemplate>
<DataTemplate>
<TabControl DockPanel.Dock="Top" ItemsSource="{Binding FileTabs}" Padding="1">
<Button Command="{Binding CloseTabCommand}" CommandParameter="TabItem" />
</TabControl>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
My question is: what argument(s?) should I be passing in CommandParameter, and how would I affect it in the ViewModel to properly remove the tab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎对如何在 WPF 中实现 MV-VM 模式没有深入的了解。看起来您知道了解 DataBinding,但您的示例演示的模式似乎缺少对 ViewModel 和命令的理解,而这些是 MVVM 真正需要的。
查看下面链接的文章及其使用的示例应用程序。您应该会发现您想要做的事情已在此处进行了演示,并且非常容易实现。
WPF 的模型-视图-视图模型 (MVVM) 设计模式
我希望这看起来不像是一种逃避,但它需要大量重新发布链接的文章才能让您到达您想去的地方。去阅读这篇文章,完成示例,如果您仍然遇到问题,请发布此问题,我会确保关注它。
It doesn't look like you have a solid understanding of how to implement an M-V-VM pattern in WPF. It looks like you know understand DataBinding but the pattern your sample demonstrates seems to be missing an understand of ViewModels and Commands, which are really required for MVVM.
Review the article linked below and the sample application it uses. You should find what you're looking to do is demonstrated here and is pretty easy to implement.
The Model-View-ViewModel (MVVM) Design Pattern for WPF
I hope that this doesn't seem like a cop-out but it would require a significant amount of re-posting of the linked article to get you where you want to go. Go read the article, work through the sample and if you still have problems, post on this question and I'll make sure to watch for it.