Close/remove view from ViewModel

Oct 13, 2011 at 11:33 PM

I use RegionManager and TabControl. When user open's view - new Tab added. It's like MDI interface for LOB application. I also do support multiple instances of the same View in my tab control. For example, user can edit 2 customers at the same time on separate tabs, etc...

Thanks to this forum I fugured how to style TabControl so I can edit/use TabItem's template. Display caption and display "close" button so user's can close tabs. TabItem being bound to my ViewModel. I added Button to my template and bound it to command. Command fires on my ViewModel. and.. Now what?! RegionManager needs View object, not ViewModel

Back to search:

2 links on a same topic point to the same sample. It doesn't look good though. First of all, I'm using region navigation with RequestNavigate. So, I don't give my view Name. Second, I have multiple instances of the same View.

The only way to handle this the way I see it - iterate through all instances of type of my View and then compare their's DataContext to my ViewModel (this)

Does it sound right? I wonder if there any cleaner way.

Oct 14, 2011 at 9:28 PM


Based on my understanding of your scenario, you might find this blog post useful, which among other things, explains how to add a view with a name to the specified region when navigating. This is achieved by implementing a custom RegionNavigationContentLoader class.

I hope you find it useful.

Agustin Adami