DelegateCommand<T> Class

An ICommand whose delegates can be attached for Execute(T) and CanExecute(T).

Namespace: Microsoft.Practices.Prism.Commands
Assembly: Microsoft.Practices.Prism.Mvvm (in Microsoft.Practices.Prism.Mvvm.dll) Version: 1.0.0.0 (1.0.0.0)

Syntax

public class DelegateCommand<T> : DelegateCommandBase
'Declaration
Public Class DelegateCommand(Of T)
    Inherits DelegateCommandBase

Type Parameters

  • T
    Parameter type.

Remarks

The constructor deliberately prevents the use of value types. Because ICommand takes an object, having a value type for T would cause unexpected behavior when CanExecute(null) is called during XAML initialization for command bindings. Using default(T) was considered and rejected as a solution because the implementor would not be able to distinguish between a valid and defaulted values.

Instead, callers should support a value type by using a nullable value type and checking the HasValue property before using the Value property.

Examples

public MyClass()
{
    this.submitCommand = new DelegateCommand<int?>(this.Submit, this.CanSubmit);
}

private bool CanSubmit(int? customerId)
{
    return (customerId.HasValue && customers.Contains(customerId.Value));
}

Inheritance Hierarchy

System.Object
  Microsoft.Practices.Prism.Commands.DelegateCommandBase
    Microsoft.Practices.Prism.Commands.DelegateCommand<T>

See Also

DelegateCommand<T> Members

Microsoft.Practices.Prism.Commands Namespace