The article introduces the basic application of region, and this article goes on to introduce the related application of region-regionadapter
1. Pre-implementation mapping relationship Regionadaptermappings
Regionadaptermappings a mapping of control and Regionadapter, which is done in the bootstrapper bootstrapper.
Protected virtual regionadaptermappings configureregionadaptermappings ()
{
regionadaptermappings Regiona Daptermappings = container.tryresolve<regionadaptermappings> ();
if (regionadaptermappings!= null)
{
regionadaptermappings.registermapping (typeof (Selector), this. Container.resolve<selectorregionadapter> ());
Regionadaptermappings.registermapping (typeof (ItemsControl), this. Container.resolve<itemscontrolregionadapter> ());
Regionadaptermappings.registermapping (typeof (ContentControl), this. Container.resolve<contentcontrolregionadapter> ());
return
regionadaptermappings;
}
Here are three kinds of control support, also explained in the previous article. Regionadapter must implement Iregionadapter interface
2. Find Regionadapter when registering region
<stackpanel cal:regionmanager.regionname= "Mainregion"/>
The above definition is wrong because the mapping relationship between StackPanel and Regionadapter cannot be found in regionadaptermappings. The settings for the attached properties will attempt to execute the following code
Protected virtual Iregion createregion (DependencyObject targetelement, string regionname)
{
//build the region
Iregionadapter regionadapter = this.regionAdapterMappings.GetMapping (Targetelement.gettype ());
Iregion region = Regionadapter.initialize (targetelement, regionname);
return region;
}
To support StackPanel, we can try to define a regional adapter that implements Iregionadapter for StackPanel.