docs.unity3d.com
Search Results for

    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
    Implements
    IRelayCommand
    ICommand
    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
    Assembly: solution.dll
    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<bool>)

    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<bool> 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
    bool

    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
    bool

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

    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.

    NotifyCanExecuteChanged()

    Notifies that the CanExecuteChanged property has changed.

    Declaration
    public void 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

    IRelayCommand
    ICommand
    In This Article
    • Constructors
      • RelayCommand(Action?)
      • RelayCommand(Action, Func<bool>)
    • Methods
      • CanExecute()
      • CanExecute(object?)
      • Execute()
      • Execute(object?)
      • NotifyCanExecuteChanged()
    • Events
      • CanExecuteChanged
    • Implements
    Back to top
    Copyright © 2024 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)