Region that allows a maximum of one active view at a time.
Inheritance: Microsoft.Practices.Composite.Presentation.Regions.Region
        public void ActivatingNewViewDeactivatesCurrent()
        {
            IRegion region = new SingleActiveRegion();
            var view = new object();
            region.Add(view);
            region.Activate(view);

            Assert.IsTrue(region.ActiveViews.Contains(view));

            var view2 = new object();
            region.Add(view2);
            region.Activate(view2);

            Assert.IsFalse(region.ActiveViews.Contains(view));
            Assert.IsTrue(region.ActiveViews.Contains(view2));
        }
Example #2
0
        /// <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="owner">The owner of the Popup.</param>
        /// <param name="regionName">The name of the <see cref="IRegion"/>.</param>
        /// <remarks>
        /// This method would typically not be called directly, instead the behavior 
        /// should be set through the Attached Property <see cref="CreatePopupRegionWithNameProperty"/>.
        /// </remarks>
        public static void RegisterNewPopupRegion(DependencyObject owner, string regionName)
        {
            // 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 = ClientIoCContainer.Container.GetInstance<IRegionManager>();
            if (regionManager != null)
            {
                IRegion region = new SingleActiveRegion();
                DialogActivationBehavior behavior = new WindowDialogActivationBehavior {HostControl = owner};

                region.Behaviors.Add(DialogActivationBehavior.BehaviorKey, behavior);
                if (!regionManager.Regions.ContainsRegionWithName(regionName))
                {
                    regionManager.Regions.Add(regionName, region);
                }
            }
        }
Example #3
0
        private static void DialogRegionNameChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
        {
            if (IsInDesignMode(o))
            {
                return;
            }

            var regionManager =
                ServiceLocator.Current.GetInstance<IRegionManager>();
            if (regionManager != null)
            {
                SingleActiveRegion region = new SingleActiveRegion();
                DialogRegionBehavior behavior = new DialogRegionBehavior();

                region.Behaviors.Add(
                    DialogRegionBehavior.DialogRegionBehaviorKey, behavior);
                behavior.HostControl = o;
                var regionName = args.NewValue as string;
                regionManager.Regions.Add(regionName, region);

            }
        }