This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- implementation | |
public class CustomBehavior : IRegionBehavior | |
{ | |
... | |
} | |
--- bootstrapper | |
protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Prism.Regions | |
{ | |
/// <summary> | |
/// Interface for allowing extensible behavior on regions. | |
/// </summary> | |
public interface IRegionBehavior | |
{ | |
/// <summary> | |
/// The region that this behavior is extending. | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IRegion Initialize(T regionTarget, string regionName) | |
{ | |
if (regionName == null) | |
throw new ArgumentNullException(nameof(regionName)); | |
IRegion region = this.CreateRegion(); | |
region.Name = regionName; | |
SetObservableRegionOnHostingControl(region, regionTarget); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// creating duplicate regions via region.add correctly throws exception | |
var region = regionManager.Regions["ViewA"]; | |
region.Add(unityContainer.Resolve<ViewA>()); | |
region.Add(unityContainer.Resolve<ViewA>()); | |
// creating duplicate regions via regionManager.AddToRegion does not throw exception | |
regionManager.AddToRegion("ViewA", unityContainer.Resolve<ViewA>()); | |
regionManager.AddToRegion("ViewA", unityContainer.Resolve<ViewA>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Uncomment the following three lines and we get exception, this gets fixed with scoped region | |
var region = regionManager.Regions["ViewA"]; | |
region.Add(unityContainer.Resolve<ViewA>()); | |
region.Add(unityContainer.Resolve<ViewA>()); | |
// the following works | |
// regionManager.AddToRegion("ViewA", unityContainer.Resolve<ViewA>()); | |
// regionManager.AddToRegion("ViewA", unityContainer.Resolve<ViewA>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IRegionManager AddToRegion(string regionName, object view) | |
{ | |
if (!Regions.ContainsRegionWithName(regionName)) | |
throw new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, Resources.RegionNotFound, regionName), nameof(regionName)); | |
return Regions[regionName].Add(view); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--ViewA.xaml | |
<ItemsControl regions:RegionManager.RegionName="RegionA"></ContentControl> | |
--ViewB.xaml | |
<ContentControl regions:RegionManager.RegionName="RegionB"></ItemsControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--ViewA.xaml | |
<ItemsControl regions:RegionManager.RegionName="RegionA"></ContentControl> | |
--ViewB.xaml | |
<ContentControl regions:RegionManager.RegionName="RegionB"></ItemsControl> | |
--ViewC.xaml | |
<ContentControl regions:RegionManager.RegionName="RegionC"></ContentControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--ViewA.xaml | |
<ItemsControl regions:RegionManager.RegionName="RegionA"></ContentControl> | |
--ViewB.xaml | |
<ItemsControl regions:RegionManager.RegionName="RegionB"></ItemsControl> | |
--ViewC.xaml | |
<ContentControl regions:RegionManager.RegionName="RegionC"></ContentControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--ViewA.xaml | |
<ContentControl regions:RegionManager.RegionName="RegionA"></ContentControl> | |
--ViewB.xaml | |
<ItemsControl regions:RegionManager.RegionName="RegionB"></ItemsControl> | |
--ViewC.xaml | |
<ContentControl regions:RegionManager.RegionName="RegionC"></ContentControl> |