wpf - Performance penalty of continuous CanExecute calls in Command -


i applying mvvm pattern project. have usercontrol has button bound command exposed viewmodel. since button visible, it's calling continuously canexecute method of button. tells me carries performance penalty, i'm not sure. expected behavior? or there better way of having button bound command?

thank you.

sorry, found out happening. implementation of relaycommand.

public class relaycommand : icommand {     #region fields      readonly action<object> _execute;     readonly predicate<object> _canexecute;      #endregion // fields      #region constructors      public relaycommand(action<object> execute)         : this(execute, null)     {     }      public relaycommand(action<object> execute, predicate<object> canexecute)     {         if (execute == null)             throw new argumentnullexception("execute");          _execute = execute;         _canexecute = canexecute;     }     #endregion // constructors      #region icommand members      [debuggerstepthrough]     public bool canexecute(object parameter)     {         return _canexecute == null ? true : _canexecute(parameter);     }      public event eventhandler canexecutechanged     {         add { commandmanager.requerysuggested += value; }         remove { commandmanager.requerysuggested -= value; }     }      public void execute(object parameter)     {         _execute(parameter);     }      #endregion // icommand members } 

i had incorrectly assumed system requerying commands automatically. hook each command's canexecutechanged event, , relaycommand links canexecutechanged event commandmanager's requerysuggested event, each time system "suggests" requery, in fact requerying relaycommands.

thank you.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -