/// <summary> /// Creates a new <see cref="IRegion"/> and registers it in the default <see cref="IRegionManager"/> /// attaching to it a <see cref="DialogActivationBehavior"/> behavior. /// </summary> /// <param name="regionName">The name of the <see cref="IRegion"/>.</param> /// <param name="windowStyle">The style to apply to the window region.</param> public static void RegisterNewWindowRegion(string regionName, Style windowStyle) { // Creates a new region and registers it in the default region manager. // Another option if you need the complete infrastructure with the default region behaviors // is to extend DelayedRegionCreationBehavior overriding the CreateRegion method and create an // instance of it that will be in charge of registering the Region once a RegionManager is // set as an attached property in the Visual Tree. var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>(); if (regionManager != null) { IRegion region = new Region(); var behavior = new WindowDialogActivationBehavior {WindowStyle = windowStyle}; region.Behaviors.Add(DialogActivationBehavior.BehaviorKey, behavior); region.Behaviors.Add(RegionActiveAwareBehavior.BehaviorKey, new RegionActiveAwareBehavior()); regionManager.Regions.Add(regionName, region); } }
/// <summary> /// Creates a new <see cref="IRegion"/> and registers it in the default <see cref="IRegionManager"/> /// attaching to it a <see cref="DialogActivationBehavior"/> behavior. /// </summary> /// <param name="regionName">The name of the <see cref="IRegion"/>.</param> /// <param name="windowStyle">The style to apply to the window region.</param> public static void RegisterNewWindowRegion(string regionName, Style windowStyle) { // Creates a new region and registers it in the default region manager. // Another option if you need the complete infrastructure with the default region behaviors // is to extend DelayedRegionCreationBehavior overriding the CreateRegion method and create an // instance of it that will be in charge of registering the Region once a RegionManager is // set as an attached property in the Visual Tree. var regionManager = ServiceLocator.Current.GetInstance <IRegionManager>(); if (regionManager != null) { IRegion region = new Region(); var behavior = new WindowDialogActivationBehavior { WindowStyle = windowStyle }; region.Behaviors.Add(DialogActivationBehavior.BehaviorKey, behavior); region.Behaviors.Add(RegionActiveAwareBehavior.BehaviorKey, new RegionActiveAwareBehavior()); regionManager.Regions.Add(regionName, region); } }