简体   繁体   中英

WPF, Different UserControl Navigation on the same TabItem

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. What I mean,is that I want to navigate through different UserControls but to stay on the same TabItem from a TabControl. I dont know how to Navigate through different ViewModels and everytime my values not to change from my 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

I think this is a good case for using pub sub with EventAggregator or MvvmLight's Messenger.

You can then loosly coupled notify the MainViewModel to exchange controls or views within a tab. Basically you can notify another ViewModel with another scope to do certain changes and then subscribe to it.

A possible structure could be: - A MainViewModel with a collection of TabItemViewModels - A single TabItemViewModel could contain also Controls and nested 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.

Check out the EventAggregator here: http://msdn.microsoft.com/en-us/library/ff921122.aspx

or check out MVVMligh Toolkit Messenger ...

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM