Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: Manage 2 regions containing 2 UserControls of same type

$
0
0
Hello,

I am facing a design problem and would like your point of view.

I have the following shell :
<ItemsControl prism:RegionManager.RegionName="ParentRegion">
   <ContentControl prism:RegionManager.RegionName="SourceRegion" />
   <ContentControl prism:RegionManager.RegionName="DestinationRegion" />
</ItemsControl>
An interface of the ViewModel contained in a "core" library shared across the libraries.
This ViewModel interface is the following :
public interface IMainRegionViewModel
    {
        string SourceText { get; set; }
        string DestText { get; set; }
    }
In my Module my initialize method set the 2 regions with the same type (MyView) :
public void Initialize()
{
      _regionManager.RegisterViewWithRegion("SourceRegion", typeof(MyView));
      _regionManager.RegisterViewWithRegion("DestinationRegion", typeof(MyView));
}
Consequently, during the creation of the MyView class, Unity injects a ViewModel of the same type in both my Views.

But I would like SourceRegion to update the field SourceText of the ParentRegion context and the DestRegion to update the field DestText of the ParentRegion.

What is the best way to do that?
  • Create 2 different view class inheriting from the same base view which only difference would be a function to override
  • Not using Unity for injecting the View in the regionManager and calling the View constructor with an argument of mine
    • I have some thoughts about implementing a delegate function as argument
  • Continue with the same code and share an event in the "Core" library that will use an EventArgs containing an information related with the View.
In fact I am looking for how to differentiate 2 Views injected by Unity in the regionManager so that they have a different behavior.

The goal of my question is : what is the best way to solve this problem?

Sincerely,
Linvi

Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>