File

projects/wms-framework/src/lib/basecomponentmodel/DependencyProperty.ts

Description

Dependency property support class

Index

Properties
Methods

Constructor

constructor(name: string, defaultValue: any, changedCallback: (sender: DependencyObject,args: DependencyPropertyChangedEventArgs) => void, propertyType?: RuntimeTypeInfo)

Creates an instance of DependencyProperty.

Parameters :
Name Type Optional
name string No
defaultValue any No
changedCallback function No
propertyType RuntimeTypeInfo Yes

Properties

Public changedCallback
Type : function
Public defaultValue
Type : any
Public name
Type : string
Public Optional propertyType
Type : RuntimeTypeInfo
Static UnsetValue
Type : any
Default value : null

Methods

Static registerNewProperty
registerNewProperty(propertyName: string, propertyType: RuntimeTypeInfo, declaringType: RuntimeTypeInfo, metadata: PropertyMetadata)

Register a new dependency property

Parameters :
Name Type Optional
propertyName string No
propertyType RuntimeTypeInfo No
declaringType RuntimeTypeInfo No
metadata PropertyMetadata No
Returns : DependencyProperty
import {
  propertyInfo,
  RuntimeTypeInfo,
} from '../baseframework/ReflectionSupport';
import { DependencyObject } from './DependencyObject';
import { DependencyPropertyChangedEventArgs } from './DependencyPropertyChangedEventArgs';
import { PropertyMetadata } from './PropertyMetadata';

/**
 * Dependency property support class
 *
 * @export
 * @class DependencyProperty
 * @wType System.Windows.DependencyProperty
 */
export class DependencyProperty {
  /**
   * Register a new dependency property
   *
   * @static
   * @param {string} propertyName
   * @param {RuntimeTypeInfo} propertyType
   * @param {RuntimeTypeInfo} declaringType
   * @param {PropertyMetadata} metadata
   * @returns {DependencyProperty}
   * @memberof DependencyProperty
   * @wMethod RegisterAttached, Register
   */
  static registerNewProperty(
    propertyName: string,
    propertyType: RuntimeTypeInfo,
    declaringType: RuntimeTypeInfo,
    metadata: PropertyMetadata
  ): DependencyProperty {
    const result = new DependencyProperty(
      propertyName,
      metadata?.defaultValue ?? null,
      metadata?.changedHandler as any,
      propertyType
    );
    return result;
  }
  /**
   * Creates an instance of DependencyProperty.
   *
   * @param {string} name
   * @param {*} defaultValue
   * @param {(sender : *,args : *) => void} changedCallback
   * @memberof DependencyProperty
   */
  constructor(
    public name: string,
    public defaultValue: any,
    public changedCallback: (
      sender: DependencyObject,
      args: DependencyPropertyChangedEventArgs
    ) => void,
    public propertyType?: RuntimeTypeInfo
  ) {}
  public static UnsetValue: any = null;
}

export class CoreDependencyProperty extends DependencyProperty {
  /**
   * Creates an instance of CoreDependencyProperty.
   *
   * @param {string} name
   * @param {*} defaultValue
   * @param {(sender : *,args : *) => void} changedCallback
   * @memberof DependencyProperty
   */
  constructor(
    name: string,
    defaultValue: any,
    propertyType: RuntimeTypeInfo,
    changedCallback: (
      sender: DependencyObject,
      args: DependencyPropertyChangedEventArgs
    ) => void
  ) {
    super(name, defaultValue, changedCallback, propertyType);
  }

  /**
   * Preprocess set value for a core dependency property
   *
   * @param {*} value
   * @returns {*}
   * @memberof CoreDependencyProperty
   */
  public preprocessSetValue(value: any): any {
    if (this.propertyType && this.propertyType.JSType === String) {
      if (value == null) {
        return '';
      }
    }

    return value;
  }
}

/**
 * Extends CoreDependencyProperty to identify when a binding should update target object
 * when the control lost focus.
 *
 * @export
 * @class FocusCoreDependencyProperty
 * @extends {CoreDependencyProperty}
 */
export class FocusCoreDependencyProperty extends CoreDependencyProperty {}

result-matching ""

    No results matching ""