[英]WPF, Different UserControl Navigation on the same TabItem
http://s7.directupload.net/images/140511/66z6w2tq.jpg http://s7.directupload.net/images/140511/66z6w2tq.jpg
As you can see on the picture I am explaining everything with a Schema, I have a TabItem and on this TabItem I want to change the DataContext everytime with a Button. 如您在图片上看到的,我正在用Schema解释所有内容,我有一个TabItem,在这个TabItem上,我想每次都使用Button更改DataContext。 What I mean,is that I want to navigate through different UserControls but to stay on the same TabItem from a TabControl. 我的意思是,我想浏览不同的UserControl,但要保留在TabControl的同一TabItem上。 I dont know how to Navigate through different ViewModels and everytime my values not to change from my Elements. 我不知道如何在不同的ViewModels中导航,并且每次我的值不更改我的Elements时都不知道。 I also could not find an Example of the same situation. 我也找不到相同情况的示例。 Any Help with a Code Snippet or a full example will be appriciated. 任何有关代码段的帮助或完整示例都将适用。 Thanks in advance. 提前致谢。
WPF/MVVM WPF / MVVM
I think this is a good case for using pub sub with EventAggregator
or MvvmLight's Messenger. 我认为这是将pub sub与EventAggregator
或MvvmLight的Messenger结合使用的好例子。
You can then loosly coupled notify the MainViewModel
to exchange controls or views within a tab. 然后,您可以松散耦合通知MainViewModel
以交换选项卡内的控件或视图。 Basically you can notify another ViewModel
with another scope to do certain changes and then subscribe to it. 基本上,您可以通知具有另一个作用域的另一个ViewModel
进行某些更改,然后订阅它。
A possible structure could be: - A MainViewModel with a collection of TabItemViewModels - A single TabItemViewModel could contain also Controls and nested ViewModels 可能的结构可能是:-带有TabItemViewModels集合的MainViewModel-单个TabItemViewModel也可以包含Controls和嵌套的ViewModels
If you want to change a tab send a ChangeTabMessage to the MainViewModel If you want to navigate within a tab use also Messaging or navigate as you do today. 如果要更改选项卡,请向MainViewModel发送一个ChangeTabMessage。如果要在选项卡中导航,也可以使用消息传递或像今天一样导航。
Check out the EventAggregator here: http://msdn.microsoft.com/en-us/library/ff921122.aspx 在此处查看EventAggregator: http : //msdn.microsoft.com/en-us/library/ff921122.aspx
or check out MVVMligh Toolkit Messenger ... 或查看MVVMligh Toolkit Messenger ...
HTH 高温超导
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.