docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class RelayCommand<T>

    Implementation of IRelayCommand that allows for CommandParameter to be passed in.

    Inheritance
    object
    RelayCommand<T>
    Implements
    IRelayCommand<T>
    IRelayCommand
    ICommand
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.AppUI.MVVM
    Assembly: Unity.AppUI.MVVM.dll
    Syntax
    public class RelayCommand<T> : IRelayCommand<T>, IRelayCommand, ICommand
    Type Parameters
    Name Description
    T

    The type of the CommandParameter.

    Constructors

    RelayCommand(Action<T?>)

    Initializes a new instance of the RelayCommand<T> class.

    Declaration
    public RelayCommand(Action<T?> execute)
    Parameters
    Type Name Description
    Action<T> execute

    The action to execute.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if the action is null.

    RelayCommand(Action<T?>, Predicate<T?>)

    Initializes a new instance of the RelayCommand<T> class.

    Declaration
    public RelayCommand(Action<T?> execute, Predicate<T?> canExecute)
    Parameters
    Type Name Description
    Action<T> execute

    The action to execute.

    Predicate<T> canExecute

    The predicate executed to determine if the command can execute.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if the action or the predicate is null.

    Methods

    CanExecute(object?)

    Determines whether this RelayCommand<T> can execute in its current state.

    Declaration
    public bool CanExecute(object? parameter)
    Parameters
    Type Name Description
    object parameter

    Data used by the command.

    Returns
    Type Description
    bool

    true if this command can be executed; otherwise, false.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if the parameter is not of type T.

    CanExecute(T?)

    Determines whether this RelayCommand<T> can execute in its current state.

    Declaration
    public bool CanExecute(T? parameter)
    Parameters
    Type Name Description
    T parameter

    Data used by the command.

    Returns
    Type Description
    bool

    true if this command can be executed; otherwise, false.

    Execute(object?)

    Executes the RelayCommand<T> on the current command target.

    Declaration
    public void Execute(object? parameter)
    Parameters
    Type Name Description
    object parameter

    Data used by the command.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if the parameter is not of type T.

    Execute(T?)

    Executes the RelayCommand<T> on the current command target.

    Declaration
    public void Execute(T? parameter)
    Parameters
    Type Name Description
    T parameter

    Data used by the command.

    NotifyCanExecuteChanged()

    Notifies that the CanExecuteChanged property has changed.

    Declaration
    public void NotifyCanExecuteChanged()

    Events

    CanExecuteChanged

    Event raised when CanExecute(object?) changes.

    Declaration
    public event EventHandler? CanExecuteChanged
    Event Type
    Type Description
    EventHandler

    Implements

    IRelayCommand<T>
    IRelayCommand
    ICommand
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)