Replacing a view in a region

Sep 2, 2008 at 2:16 PM
Edited Sep 2, 2008 at 2:17 PM
Hi guys,

We have a few abstractions put in place over Prism as we wanted to get away from the depedency model that's presented (i.e. our modules know very little about Prism and only deal with regions).

Our controller (similar to IModule) has a launch method that will get called when the application controller calls it (bound to a listbox with a list of dynamic modules that are loaded at runtime). Launch just calls:


// view is actually constructed by a factory which handles the binding of the view to the model but that's not important here
// regionManager is of type IRegionManager

What I *want* to do is swap the view in, replacing the old view (maybe using some kind of transition).

Not sure how to do this as I don't want to get into view management inside of each module. Ideas?
Sep 2, 2008 at 5:06 PM

What if you simply used a custom TabControl that does not show tabs? The control would be your RegionNames.MainRegion. This cusotm control could also have a property that exposes an interface so that you could assign different types of transitions.

Just a thought,

Andres Olivares
Sep 2, 2008 at 6:54 PM

That makes sense. I'll spike something out to see if that would work.

Sep 4, 2008 at 7:04 PM
Edited Sep 4, 2008 at 7:05 PM

I've changed my ItemsControl to a TabControl and it shows up. I'm not sure when the view is launched how to hook into the control (without exposing the control itself).

Here's my tab control:

            Regions:RegionManager.RegionName="{x:Static UserInterface:RegionNames.TaskExecutionRegion}"
            Grid.Column="1" Grid.Row="1" Name="tabControl1" >
                    <TabItem Header="tabItem1" Name="tabItem1">
                        <Grid />

This isn't what I want because when I select a module it adds a new tab. Not sure where the logic should go for finding a tab and activating it (or adding a new tab) or how that would get access to the control.

Sep 5, 2008 at 3:18 PM

I would approach your issue in the following steps:

1. Create a custom control that handles your view transitions.
2. Regionalize your control and interact with it to Add/Activate module views

<!--Custom Control - TransitionControl-->
<TabControl x:Name="root"/>
<!--Should implement non-visible tabs, transitions and state management for each view contained-->

<Window x:Name="root"
  <!-- Module selector-->
  <ListBox x:Name="moduleListBox" SelectionChanged="moduleSelected"/>
  <!--Region for custom control-->
  <ContentControl x:Name="moduleManager" cal:RegionManager.RegionName="ModuleManagerArea">
   <!--Style for type of custom control-->
    <Style TargetType="{x:Type self:TransitionControl}">
     <!--Example of transition assignment-->
     <Setter Property="Transition" Value="{StaticResource moduleTransition}" />

// Bootstrapper.cs
// Resolve UI items
control = Container.Resolve<TransitionControl>();
// Get region management objects
var regionManager = Container.Resolve<IRegionManager>();
var region = regionManager.Regions["ModuleManagerArea"];
// regionalize your custom control

void moduleSelected(object sender, RoutedEventArgs e)
 IModule module = GetModule(moduleManager.SelectedItem);
 //SpecificModule would be your custom module
 object view = (module as SpecificModule).GetUserView();
 // Retrieve TransitionControl
 TransitionControl transitionControl = moduleManager.Content as TransitionControl;
 // Your custom control would manage the addition of a new view or activate a new request
 // The custom control would use the transtion defined to animate switching views

You do not have to regionalize your custom control, but I added that in their if you were interested in a way of extracting regionalized views and setting custom properties for you regionalized view in a clean way.

Hope this helps,

Andres Olivares