I am applying the MVVM pattern to a project. I have a UserControl which has a button which is bound to a command exposed by the ViewModel. Since the button is visible, It will continue to call the button’s CanExecute method. Something tells me that this will cause a performance loss, but I’m not sure. Is this the expected behavior? Or is there a better way to bind buttons to commands?
Thank you.
Sorry, I found out what happened Matter. This is the implementation of RelayCommand.
public class RelayCommand: ICommand { #region Fields < br /> readonly Action
I mistakenly believe that the system automatically re-query all commands. What it actually does is hook the CanExecuteChanged event of each Command, and RelayCommand Basically link its CanExecuteChanged event to the CommandManager’s RequerySuggested event, so every time the system “suggests” a requery, it is actually requerying all of my RelayCommands.
Thank you.
< /div>
I am applying the MVVM pattern to the project. I have a UserControl which has a button which is bound to a command exposed by the ViewModel. Since the button is visible, it is The button’s CanExecute method is continuously called. Something tells me that this will cause performance loss, but I’m not sure. Is this the expected behavior? Or is there a better way to bind buttons to commands?
Thank you.
Sorry, I found out what happened. This is the implementation of RelayCommand. < p>
public class RelayCommand: ICommand { #region Fields
public void Execute(object parameter) { _execute(parameter); }
#endregion // ICommand Members }
< p>I mistakenly think that the system automatically re-query all commands. What it actually does is hook the CanExecuteChanged event of each Command, and RelayCommand basically links its CanExecuteChanged event to the RequerySuggested event of the CommandManager, so every time the system “suggests” When a requery is made, it is actually requerying all of my RelayCommands.