/// <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); } } } }
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); } } } }
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); } } }
/// <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); } } } }