Passing data from view to view model (TabControl within a Prism region)

Topics: Prism v4 - WPF 4
Nov 11, 2012 at 3:02 PM
Edited Nov 11, 2012 at 3:03 PM

I am using TabControl in a Prism region like this:

<UserControl ... >

<ListBox ... />

 <TabControl prism:RegionManager.RegionName="TabRegion">
    <!-- The views that were declared in XAML are removed -->       


Each tab is a UserControl with a viewmodel associated with it. Everything works fine (I can add new tab using RegisterViewWithRegion, tab headers are shown correctly, etc.)

In the same view I have a ListBox. The question is how to pass the selected item in the ListBox to the viewmodel of each tab?

Thanks a lot.

Nov 12, 2012 at 2:20 PM
Edited Nov 12, 2012 at 2:23 PM


In my opinion a possible approach to achieve this kind of scenarios could be by benefiting of the RegionContext attached property provided with the region manager, which will allow you to share to share context from a parent view that hosts a region to its child views. This way, you could set the region context property of your "TabRegion" with the SelectedItem value of your ListBox control to pass it to the views in the region, for example like this:

<TabControl prism:RegionManager.RegionName="TabRegion"  prism:RegionManager.RegionContext="{Binding ElementName=myListBox,Path=SelectedItem}" />

For more detailed information about this approach and other possible approaches to communicate between views, I recommend you to check the following sections of the documentation:

Also, you could find an useful example that portrays this approach in the UI Composition QuickStart provided with Prism

I hope you find this handy,

Agustin Adami

Nov 13, 2012 at 1:37 AM

It works! Thank you aadami.