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: (


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

Type Parameters

  • T
    Parameter type.


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.


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


See Also

DelegateCommand<T> Members

Microsoft.Practices.Prism.Commands Namespace