Are there any performance implications in CanExecuteCommand?

What are the implications of using the CanExecuteCommand ICommand object. Does this method repeat over and over?

I need to iterate through a collection of approximately 200 objects, based on which she decided whether the button bound to the command should be enabled? CanExecuteCommand runs again, which slows down my application.

+5
source share
2 answers

The interface is ICommandas follows:

public interface ICommand
{
    // two methods
    bool CanExecute(object parameter);
    void Execute(object parameter);

    // one event
    event EventHandler CanExecuteChanged;
}

CanExecuteChanged , , CanExecute / WPF. , ICommand, , , GUI ( WPF), , CanExecute.

Josh Smith RelayCommand CommandManager WPF CanExecuteChanged:

public event EventHandler CanExecuteChanged
{
    add { CommandManager.RequerySuggested += value; }
    remove { CommandManager.RequerySuggested -= value; }
}

, WPF CommandManager - , : KeyUpEvent, MouseUpEvent .., ", - ", RequerySuggested. , RelayCommand, CanExecute , CommandManager , - ( ). 50 , , , 50 . , . , CanExecute , , , . : API CanExecute.

CommandManager.RequerySuggested, ICommand.CanExecuteChanged, RelayCommand, CanExecuteChanged , Prism DelegateCommand, CommandManager, CanExecuteChanged, , , , PropertyChanged, CanExecuteChanged .

@Will , . RelayCommand, , 80% . , RelayCommand Prism DelegateCommand CanExecuteChanged .

+13

: . -, OnPropertyChanged ViewModelBase, CanExecuteChanged Command , , One Way . PerrypheralFrameowrk.WPF, nuget codeplex. . Codeplex wiki , .

0

All Articles