使用WPF关闭嵌套选项卡? [英] Closing nested tabs using WPF?

查看:111
本文介绍了使用WPF关闭嵌套选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设计一个包含嵌套选项卡的UI,但是我似乎找不到有关如何以MVVM方式删除嵌套选项卡的信息.

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.

这是我的XAML(为简洁起见,它已被剪除):

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>

我的问题是:我应该在CommandParameter中传递什么参数,以及如何影响它在ViewModel中正确删除选项卡?

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?

推荐答案

您似乎不太了解如何在WPF中实现M-V-VM模式.您似乎了解DataBinding,但您的示例演示的模式似乎缺少对ViewModels和Commands的理解,而MVVM确实需要ViewModels和Commands.

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.

用于WPF的模型-视图-视图模型(MVVM)设计模式

我希望这似乎不是一个解决方案,但是它需要对链接的文章进行大量的重新发布才能使您到达想要去的地方.请阅读本文,研究示例,如果仍然有问题,请发布此问题,我将确保您予以注意.

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.

这篇关于使用WPF关闭嵌套选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆