File

projects/wms-framework/src/lib/regionsframework/adapters/behaviors/AutoPopulateRegionBehavior.ts

Description

Behavior for populate the region when a view is registered to it.

Extends

RegionBehavior

Index

Properties
Methods

Constructor

constructor(registry: IRegionViewRegistry)

Creates an instance of AutoPopulateRegionBehavior.

Parameters :
Name Type Optional
registry IRegionViewRegistry No

Properties

Static Readonly BehaviorKey
Type : string
Default value : 'AutoPopulate'

TabControlRegionSyncBehavior key used to register the behavior in the collection

regionViewRegistry
Type : IRegionViewRegistry
IsAttached
Type : boolean
Inherited from RegionBehavior
Defined in RegionBehavior:37

Value indicating that the region behavior is attached

region
Type : IRegion
Inherited from RegionBehavior
Defined in RegionBehavior:45

Methods

Public OnAttach
OnAttach()
Inherited from RegionBehavior
Defined in RegionBehavior:68

Override this method to perform the logic after the behavior has been attached.

Returns : void
Public OnViewRegistered
OnViewRegistered(sender: unknown, eventArgs: ViewRegisteredEventArgs)
Parameters :
Name Type Optional
sender unknown No
eventArgs ViewRegisteredEventArgs No
Returns : void
Attach
Attach()
Inherited from RegionBehavior
Defined in RegionBehavior:75

Attaches the behavior to the region

Returns : void
import { RegionBehavior } from '../../RegionBehavior';
import { injectable, inject } from 'tsyringe';
import { IRegionViewRegistry } from '../../IRegionViewRegistry';
import { regionViewRegistryInjectionToken } from '../../injectionTokens';
import { ViewRegisteredEventArgs } from '../../events/ViewRegisteredEventArgs';

/**
 * Behavior for populate the region when a view is registered to it.
 *
 * @export
 * @class TabControlRegionSyncBehavior
 * @extends {RegionBehavior}
 * @implements {IHostAwareRegionBehavior}
 * @wType Microsoft.Practices.Prism.Regions.Behaviors.AutoPopulateRegionBehavior
 */
@injectable()
export class AutoPopulateRegionBehavior extends RegionBehavior {
  /**
   * TabControlRegionSyncBehavior key used to register the behavior in the collection
   *
   * @static
   * @type {string}
   * @memberof TabControlRegionSyncBehavior
   */
  public static readonly BehaviorKey: string = 'AutoPopulate';

  /**
   * Region view registry
   *
   * @type {IRegionViewRegistry}
   * @memberof AutoPopulateRegionBehavior
   */
  #regionViewRegistry: IRegionViewRegistry;

  /**
   *Creates an instance of AutoPopulateRegionBehavior.
   * @param {IRegionViewRegistry} registry
   * @memberof AutoPopulateRegionBehavior
   */
  constructor(
    @inject(regionViewRegistryInjectionToken) registry: IRegionViewRegistry
  ) {
    super();
    this.#regionViewRegistry = registry;
  }

  /**
   *
   * Override this method to perform the logic after the behavior has been attached.
   *
   */
  public OnAttach(): void {
    if (!!this.Region.Name) {
      this.#regionViewRegistry.ContentRegistered.addHandler((s, e) =>
        this.OnViewRegistered(s, e)
      );
    }
  }

  public OnViewRegistered(
    sender: unknown,
    eventArgs: ViewRegisteredEventArgs
  ): void {
    if (eventArgs == null) {
      throw new Error('Argument null exception in parameter eventArgs');
    }
    if (eventArgs.RegionName == this.Region.Name) {
      this.Region.Add(eventArgs.GetView());
    }
  }
}

result-matching ""

    No results matching ""