i trying use custom delegate command
but, automatic raisecanexecutechanged not work properly. nice use commandmanagerhelper (every time when application in focus, raise canexecute changed every command? or have use standart relaycommand , raise canexecutechanged myself ?
thanks
the raisecanexecutechanged event not work in automated mode. there such implementation every ui interaction refresh canexecute handlers requerysuggested event. code follows (keep in mind, implementation of icommand not performance effective, works charm):
public class command<targs> : icommand { public command(action<targs> exdelegate) { _exdelegate = exdelegate; } public command(action<targs> exdelegate, func<targs, bool> candelegate) { _exdelegate = exdelegate; _candelegate = candelegate; } protected action<targs> _exdelegate; protected func<targs, bool> _candelegate; #region icommand members public bool canexecute(targs parameter) { if (_candelegate == null) return true; return _candelegate(parameter); } public void execute(targs parameter) { if (_exdelegate != null) { _exdelegate(parameter); } } public event eventhandler canexecutechanged { add { commandmanager.requerysuggested += value; } remove { commandmanager.requerysuggested -= value; } } bool icommand.canexecute(object parameter) { if (parameter != null) { var parametertype = parameter.gettype(); if (parametertype.fullname.equals("ms.internal.namedobject")) return false; } return canexecute((targs)parameter); } void icommand.execute(object parameter) { execute((targs)parameter); } #endregion }
Comments
Post a Comment