docs.unity3d.com
    Show / Hide Table of Contents

    Class RelayCommand<T>

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

    Inheritance
    Object
    RelayCommand<T>
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.AppUI.MVVM
    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(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
    Boolean

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

    Implements
    IRelayCommand<T>.CanExecute(T)

    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
    Boolean

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

    Implements
    ICommand.CanExecute(Object)
    Exceptions
    Type Condition
    InvalidOperationException

    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.

    Implements
    IRelayCommand<T>.Execute(T)

    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.

    Implements
    ICommand.Execute(Object)
    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if the parameter is not of type T.

    NotifyCanExecuteChanged()

    Notifies that the CanExecuteChanged property has changed.

    Declaration
    public void NotifyCanExecuteChanged()
    Implements
    IRelayCommand.NotifyCanExecuteChanged()

    Events

    CanExecuteChanged

    Event raised when CanExecute(Object) changes.

    Declaration
    public event EventHandler CanExecuteChanged
    Event Type
    Type Description
    EventHandler
    Implements
    ICommand.CanExecuteChanged
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023