wpf - does invokecommandaction use canexecute? -
i new wpf , interactivity. trying execute command based on event trigger. in code below, when doubleclick event trigger, canexecute invoked , return false execute function still called. default behavior invokecommandaction? think when can execute returns false, execute not called.
<usercontrol x:class="..." xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"> <i:interaction.triggers> <i:eventtrigger eventname="mousedoubleclick"> <i:invokecommandaction command="{binding path=displayreportcommand}"/> </i:eventtrigger> </i:interaction.triggers> ...
yes use canexecute , command not execute if return false. have posted code example.
here command in viewmodel class
relaycommand _showmessagecommand; public icommand showmessagecommand { { if (_showmessagecommand == null) { _showmessagecommand = new relaycommand(param => this.showmessage(), param => this.canshowmessage); } return _showmessagecommand; } } public void showmessage() { messagebox.show("nitesh"); } private bool canshowmessage { { return false; // set true execute command } }
and how use in xaml
<button content="nitesh"> <i:interaction.triggers> <i:eventtrigger eventname="mousedoubleclick"> <i:invokecommandaction command="{binding showmessagecommand}" ></i:invokecommandaction> </i:eventtrigger> </i:interaction.triggers> </button>
Comments
Post a Comment