/// <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); } } } }
public void Add(string key, IRegionBehavior regionBehavior) { if (key == null) throw new ArgumentNullException("key"); if (regionBehavior == null) throw new ArgumentNullException("regionBehavior"); if (this.behaviors.ContainsKey(key)) throw new ArgumentException("Could not add duplicate behavior with same key.", "key"); this.behaviors.Add(key, regionBehavior); regionBehavior.Region = this.region; regionBehavior.Attach(); }
/// <summary> /// Adds a <see cref="IRegionBehavior"/> to the collection, using the specified key as an indexer. /// </summary> /// <param name="key">The key that specifies the type of <see cref="IRegionBehavior"/> that's added.</param> /// <param name="regionBehavior">The <see cref="IRegionBehavior"/> to add.</param> /// <exception cref="ArgumentNullException"> /// Thrown is the <paramref name="key"/> parameter is Null, /// or if the <paramref name="regionBehavior"/> parameter is Null. /// </exception> /// <exception cref="ArgumentException">Thrown if a behavior with the specified Key parameter already exists.</exception> public void Add(string key, IRegionBehavior regionBehavior) { if (key == null) throw new ArgumentNullException("key"); if (regionBehavior == null) throw new ArgumentNullException("regionBehavior"); if (this.behaviors.ContainsKey(key)) throw new ArgumentException("Could not add duplicate behavior with same key.", "key"); this.behaviors.Add(key, regionBehavior); regionBehavior.Region = this.region; regionBehavior.Attach(); }
/// <summary> /// Adds a <see cref="IRegionBehavior"/> to the collection, using the specified key as an indexer. /// </summary> /// <param name="key">The key that specifies the type of <see cref="IRegionBehavior"/> that's added.</param> /// <param name="regionBehavior">The <see cref="IRegionBehavior"/> to add.</param> /// <exception cref="ArgumentNullException"> /// Thrown is the <paramref name="key"/> parameter is Null, /// or if the <paramref name="regionBehavior"/> parameter is Null. /// </exception> /// <exception cref="ArgumentException">Thrown if a behavior with the specified Key parameter already exists.</exception> public void Add(string key, IRegionBehavior regionBehavior) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (regionBehavior == null) { throw new ArgumentNullException(nameof(regionBehavior)); } if (_behaviors.ContainsKey(key)) { throw new ArgumentException("Could not add duplicate behavior with same key.", nameof(key)); } _behaviors.Add(key, regionBehavior); regionBehavior.Region = _region; regionBehavior.Attach(); }
/// <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); } } } }