コード例 #1
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 = RegionBehaviorFactory;

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

                        if (regionTarget is VisualElement visualElementRegionTarget)
                        {
                            if (behavior is IHostAwareRegionBehavior hostAwareRegionBehavior)
                            {
                                hostAwareRegionBehavior.HostControl = visualElementRegionTarget;
                            }
                        }

                        region.Behaviors.Add(behaviorKey, behavior);
                    }
                }
            }
        }
コード例 #2
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);
             }
         }
     }
 }
コード例 #3
0
            private void RegisterDefaultBehavior(IRegion region)
            {
                var enumerator = _regionBehaviorFactory.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    var behaviorKey = enumerator.Current;
                    if (!region.Behaviors.ContainsKey(behaviorKey))
                    {
                        var behavior = _regionBehaviorFactory.CreateFromKey(behaviorKey);
                        region.Behaviors.Add(behaviorKey, behavior);
                    }
                }
            }
コード例 #4
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);
                    }
                }
            }
        }