File

projects/wms-framework/src/lib/infra/Commanding.ts

Description

Commanding attached properties

Index

Properties
Methods

Properties

Static CommandProperty
Default value : new DependencyProperty( 'Infra_Command', null, commandChanged )

Sets the command

Methods

Static SetCommand
SetCommand(sender: FrameworkElement, source: CommandSource)
Parameters :
Name Type Optional
sender FrameworkElement No
source CommandSource No
Returns : void
import { DependencyObject } from '../basecomponentmodel/DependencyObject';
import { DependencyProperty } from '../basecomponentmodel/DependencyProperty';
import { DependencyPropertyChangedEventArgs } from '../basecomponentmodel/DependencyPropertyChangedEventArgs';
import { FrameworkElement } from '../basecomponentmodel/FrameworkElement';
import { SubscriptionEvent } from '../utils/SubscriptionEvent';
import { CommandSource } from './CommandSource';

/**
 * Callback for command changed
 *
 * @export
 * @param {DependencyObject} sender
 * @param {DependencyPropertyChangedEventArgs} args
 */
export function commandChanged(
  sender: DependencyObject,
  args: DependencyPropertyChangedEventArgs
) {
  if (
    args.NewValue instanceof CommandSource &&
    typeof args.NewValue.EventName === 'string' &&
    sender[args.NewValue.EventName] instanceof SubscriptionEvent
  ) {
    const resolvedCommand = args.NewValue.Command;
    sender[args.NewValue.EventName].addHandler(() =>
      resolvedCommand.Execute(args.NewValue.ParameterResolved)
    );
  }
}

/**
 *  Commanding attached properties
 *
 * @export
 * @class Commanding
 * @wType Infragistics.Controls.Commanding
 */
export class Commanding {
  /**
   * Sets the command
   *
   * @static
   * @memberof Commanding
   */
  public static CommandProperty = new DependencyProperty(
    'Infra_Command',
    null,
    commandChanged
  );

  public static SetCommand(sender: FrameworkElement, source: CommandSource) {
    sender.setValue(Commanding.CommandProperty, source);
  }
}

result-matching ""

    No results matching ""