docs.unity3d.com
    Show / Hide Table of Contents

    Class RelayCommand

    A command whose sole purpose is to relay its functionality to other objects by invoking delegates. The default return value for the CanExecute(Object) method is true. This type does not allow you to accept command parameters in the Execute(Object) and CanExecute(Object) callback methods.

    Inheritance
    Object
    RelayCommand
    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 : IRelayCommand, ICommand

    Constructors

    RelayCommand(Action)

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

    Declaration
    public RelayCommand(Action execute)
    Parameters
    Type Name Description
    Action execute

    The action to execute.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if the action is null.

    RelayCommand(Action, Func<Boolean>)

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

    Declaration
    public RelayCommand(Action execute, Func<bool> canExecute)
    Parameters
    Type Name Description
    Action execute

    The action to execute.

    Func<Boolean> canExecute

    Predicate used to determine if the command can execute.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if the action is null.

    Methods

    CanExecute()

    Initializes a new instance of the RelayCommand class.

    Declaration
    public bool CanExecute()
    Returns
    Type Description
    Boolean

    CanExecute(Object)

    Determines whether this RelayCommand 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)

    Execute()

    Defines the method to be called when the command is invoked.

    Declaration
    public void Execute()

    Execute(Object)

    Executes the RelayCommand 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)

    NotifyCanExecuteChanged()

    Notifies that the CanExecuteChanged property has changed.

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

    Events

    CanExecuteChanged

    Occurs when changes occur that affect whether or not the command should execute.

    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