Open second shell in prism v4 WPF application (areas)

I have a prism application containing Shell.xaml (with MainRegion), ShellViewModel.cs.

This shell window opens when the application starts. Now I want to open a second popup containing the same shell window (Shell.xaml, ShellViewModel).

A shell is defined as an example of the StockTraderRI prism. Shell.xaml contains MainRegion (a very simplified source):

<Window x:Class="Bsoft.Test.Shell" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.codeplex.com/CompositeWPF" Title="MainWindow" Height="550" Width="825"> <Grid> <ContentControl cal:RegionManager.RegionName="MainRegion"/> </Grid> </Window> 

The code behind contains only the base ViewModel link:

 namespace Bsoft.Test.bmedApp { [Export] public partial class Shell : Window { [ImportingConstructor] public Shell() { InitializeComponent(); } [Import] ShellViewModel ViewModel { set { this.DataContext = value; } } } } 

ShellViewModel is automatically installed by the MEF loader:

 namespace Bsoft.Test.bmedApp { [Export] public class ShellViewModel : NotificationObject { [ImportingConstructor] public ShellViewModel() { } } } 

This works as intended.

Now I want to open the shell window a second time as a popup. It is easy to see that Shell and ViewModel are not shared with:

 [PartCreationPolicy(CreationPolicy.NonShared)] 

But my problems are:

1) I load another view (models) in MainRegion. How do I tell the program whether the View (Model) should be loaded into the main Shell MainRegion main file or into the MainRegion popup? I think I need RegionManagers cloud managers, but I did not understand how to use them for this.

2) I have some events (EventAggregator) for views loaded in the region, for sending notifications and commands (status update, closing the view, errors) for the Shell report. How can I separate the main shell events from the popup window events (since they are both the same shell)?

I want to be able to open several pop-ups, so it’s not enough for me to use different names of the regions, I need more separation. Maybe there is a way to create a separate internal prism / fur / area / container infrastructure?

+4
source share
2 answers

I don’t quite understand what you mean by opening two shells? If you run the silverlight application in two different windows or you have 2 instances of your WPF application, your shells do not conflict. Even if you have one application with two instances of Bootstrapper, there is no conflict - your two shells work completely independently. Let me know if this help helps.

+1
source

What you are trying to achieve is possible, although there may be some things that I don’t quite understand about your approach.

I assume that when you talk about having two shells, you actually mean having two active windows at the same time.

There are many ways to achieve this in Prism, so let's continue your doubts.

For (1), the best I can come up with is to create another instance of the area manager associated with another shell (popup). This is similar to working with regions with a region (since you will have a separate RegionManager), but you create a manager and attach it to the shell. Then register the new RegionManager in MEF with a row identifier so that you can distinguish it from the MainWindow RegionManager and simply add the regions to the correct region manager.

(2) is a different subject since you are trying to get the same code to behave differently. Perhaps if you need such different behaviors, using the same wrapper class for both windows is not the best approach. If you need such differentiability, but I would still like to use the code, I would recommend using some form of inheritance and combining virtual methods in BaseShell with template methods to perform different actions for each shell.

Hope this illustrates my point.

+1
source

All Articles