コード例 #1
0
ファイル: RegionAdapterBase.cs プロジェクト: 598235031/Prism
 protected virtual void AttachDefaultBehaviors(IRegion region, T regionTarget)
 {
     if (region == null) throw new ArgumentNullException("region");
     if (regionTarget == null) throw new ArgumentNullException("regionTarget");
     IRegionBehaviorFactory behaviorFactory = this.RegionBehaviorFactory;
     if (behaviorFactory != null)
     {
         DependencyObject dependencyObjectRegionTarget = regionTarget as DependencyObject;
         foreach (string behaviorKey in behaviorFactory)
         {
             if (!region.Behaviors.ContainsKey(behaviorKey))
             {
                 IRegionBehavior behavior = behaviorFactory.CreateFromKey(behaviorKey);
                 if (dependencyObjectRegionTarget != null)
                 {
                     IHostAwareRegionBehavior hostAwareRegionBehavior = behavior as IHostAwareRegionBehavior;
                     if (hostAwareRegionBehavior != null)
                     {
                         hostAwareRegionBehavior.HostControl = dependencyObjectRegionTarget;
                     }
                 }
                 region.Behaviors.Add(behaviorKey, behavior);
             }
         }
     }
 }
コード例 #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="CreateWindowRegionWithNameProperty"/>.
        /// </remarks>
        public static void RegisterNewWindowRegion(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.
            IRegionManager regionManager = ServiceLocator.Current.GetInstance <IRegionManager>();

            if (regionManager != null)
            {
                IRegion region = new AllActiveRegion();
                IHostAwareRegionBehavior behavior = ServiceLocator.Current.GetInstance <DialogActivationBehavior>();
                behavior.HostControl = owner;

                region.Behaviors.Add(DialogActivationBehavior.BehaviorKey, behavior);
                regionManager.Regions.Add(regionName, region);
            }
        }
コード例 #3
0
        /// <summary>
        /// This method adds the default behaviors by using the <see cref="IRegionBehaviorFactory"/> object.
        /// </summary>
        /// <param name="region">The region being used.</param>
        /// <param name="regionTarget">The object to adapt.</param>
        protected virtual void AttachDefaultBehaviors(IRegion region, T regionTarget)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            if (regionTarget == null)
            {
                throw new ArgumentNullException(nameof(regionTarget));
            }

            IRegionBehaviorFactory behaviorFactory = this.RegionBehaviorFactory;

            if (behaviorFactory != null)
            {
                AvaloniaObject AvaloniaObjectRegionTarget = regionTarget as AvaloniaObject;

                foreach (string behaviorKey in behaviorFactory)
                {
                    if (!region.Behaviors.ContainsKey(behaviorKey))
                    {
                        IRegionBehavior behavior = behaviorFactory.CreateFromKey(behaviorKey);

                        if (AvaloniaObjectRegionTarget != null)
                        {
                            IHostAwareRegionBehavior hostAwareRegionBehavior = behavior as IHostAwareRegionBehavior;
                            if (hostAwareRegionBehavior != null)
                            {
                                hostAwareRegionBehavior.HostControl = AvaloniaObjectRegionTarget;
                            }
                        }

                        region.Behaviors.Add(behaviorKey, behavior);
                    }
                }
            }
        }