Executing Commands from *any* event<p>I understand that commands can be triggered off certain events of certain controls.   For example, specifying  a Command for a Button will trigger it off the Click event.  But what if I wanted to trigger a command off of a different event -- like a Load event?  Is there a way to do this at all?  If so, can I do it from XAML only? </p>© 2009 Microsoft Corporation. All rights reserved.Mon, 06 Apr 2009 22:44:58 Za078bab6-7068-427d-90fb-b08ee723928fhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#a078bab6-7068-427d-90fb-b08ee723928fhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#a078bab6-7068-427d-90fb-b08ee723928fwpf michellehttp://social.msdn.microsoft.com/Profile/en-US/?user=wpf%20michelleExecuting Commands from *any* event<p>I understand that commands can be triggered off certain events of certain controls.   For example, specifying  a Command for a Button will trigger it off the Click event.  But what if I wanted to trigger a command off of a different event -- like a Load event?  Is there a way to do this at all?  If so, can I do it from XAML only? </p>Fri, 04 Aug 2006 13:37:01 Z2006-08-21T21:01:48Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#3f40f4c2-b49d-4824-866a-15243e186df3http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#3f40f4c2-b49d-4824-866a-15243e186df3Brownie Pointshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brownie%20PointsExecuting Commands from *any* event<P>Create a handler for the event and call RoutedCommand.Execute within your handler. I'm not sure if you should call CanExecute first or if Execute will check for you. (To err on the safe side call CanExecute first.) </P> <P>If you want this to be done strictly through XAML, you&nbsp;would need to derive a class from TriggerAction that fires a command and add it to an EventTrigger within XAML. If people think this utility would be useful, I could add it as a WorkItem for the WPF Toolbelt project.</P>Fri, 04 Aug 2006 18:11:03 Z2006-08-09T15:27:56Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#a745dfc5-b6d9-4327-8e75-4d1ba8feee29http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#a745dfc5-b6d9-4327-8e75-4d1ba8feee29lukemeliahttp://social.msdn.microsoft.com/Profile/en-US/?user=lukemeliaExecuting Commands from *any* event<span><span id="_ctl0_MainContent__ctl0_PostForm_ReplyBody" class=txt4><span style="color:rgb(153, 51, 102);font-family:Verdana,Geneva,Arial,Sans-serif">If you want this to be done strictly through XAML, you would need to derive a class from TriggerAction that fires a command and add it to an EventTrigger within XAML. If people think this utility would be useful, I could add it as a WorkItem for the WPF Toolbelt project.</span><br style="font-family:Verdana,Geneva,Arial,Sans-serif"><br style="font-family:Verdana,Geneva,Arial,Sans-serif"><span style="font-family:Verdana,Geneva,Arial,Sans-serif">I would find this useful...</span><br></span></span>Fri, 04 Aug 2006 19:57:57 Z2006-08-04T19:57:57Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#67b066af-dad7-4c37-974b-7cc6c9c04625http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#67b066af-dad7-4c37-974b-7cc6c9c04625wpf michellehttp://social.msdn.microsoft.com/Profile/en-US/?user=wpf%20michelleExecuting Commands from *any* event<p>Yes, that would be a very useful utility.   Thanks Mike! </p>Mon, 07 Aug 2006 13:58:17 Z2006-08-07T13:58:17Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#263eb460-f071-4774-bf23-826014894c6fhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#263eb460-f071-4774-bf23-826014894c6fBrownie Pointshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brownie%20PointsExecuting Commands from *any* eventDone, the tool is scheduled for the WPF Toolbelt CTP 2 release scheduled for the end of August. If the class is available prior to the official release date (through a code commit) I will let you know here. If you'd like to follow the project, you can go <a title="http://www.codeplex.com/Wiki/View.aspx?ProjectName=wpftoolbelt" href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=wpftoolbelt">here</a>Mon, 07 Aug 2006 15:04:34 Z2006-08-07T15:04:34Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#67e0cfbb-526e-4b75-94f2-2e4cd8212153http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#67e0cfbb-526e-4b75-94f2-2e4cd8212153wpf michellehttp://social.msdn.microsoft.com/Profile/en-US/?user=wpf%20michelleExecuting Commands from *any* event<p>I looked into this further, and it doesn't seem that deriving from TriggerAction will work, since TriggerAction class is &quot;public abstract&quot; but it has 2 &quot;internal abstract&quot; methods [2 overloads for Invoke].  </p> <p>Any plans from MS to change this?   This could be really useful...</p>Wed, 09 Aug 2006 15:27:30 Z2006-08-21T20:50:38Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#4e52bbeb-7492-4412-8843-002fc1001cc1http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#4e52bbeb-7492-4412-8843-002fc1001cc1Brownie Pointshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brownie%20PointsExecuting Commands from *any* eventWell that's not fair. And looking at the implementation of its derived classes, you can't override behavior with them either.Wed, 09 Aug 2006 18:30:09 Z2006-08-09T18:30:09Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#f084b664-a01a-4ca7-b5b1-3152d93ab6a1http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#f084b664-a01a-4ca7-b5b1-3152d93ab6a1Brownie Pointshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brownie%20PointsExecuting Commands from *any* eventI just logged a feature request on the feedback site. <a title="http://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=178608&amp;SiteID=212" href="http://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=178608&amp;SiteID=212"><u><font color="#810081">Go here to vote and add a comment</font></u></a>. Hopefully this is something that can be added in time for the final version.Wed, 09 Aug 2006 18:46:41 Z2006-08-10T14:41:39Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#999764c8-2c97-4815-8742-91ce3327edd3http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#999764c8-2c97-4815-8742-91ce3327edd3wpf michellehttp://social.msdn.microsoft.com/Profile/en-US/?user=wpf%20michelleExecuting Commands from *any* eventI agree.  Thanks Mike!<br>Thu, 10 Aug 2006 14:42:51 Z2006-08-10T14:42:51Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#ba16e0b5-c2f6-4a2e-82d1-2a1af6245160http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#ba16e0b5-c2f6-4a2e-82d1-2a1af6245160Brownie Pointshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brownie%20PointsExecuting Commands from *any* event<p>This is the feedback from Msft on the issue</p> <p><div class=quote><table width="85%"><tr><td class=txt4> <strong>Microsoft wrote:</strong></td></tr><tr><td class=quoteTable><table width="100%"><tr><td width="100%" valign=top class=txt4>This is by design for this version. We do understand that this is a valuable feature and are considering it for future versions. </p> <p>Thanks for the feedback!</td></tr></table></td></tr></table></div></p> <p>Looks like we won't get it with V1 <img src="images/emoticons/smile_sniff.gif"></p>Thu, 17 Aug 2006 19:50:01 Z2006-08-21T21:01:48Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#31a32d6e-c28c-4d68-959b-4a6e9830ca96http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a078bab6-7068-427d-90fb-b08ee723928f#31a32d6e-c28c-4d68-959b-4a6e9830ca96Brownie Pointshttp://social.msdn.microsoft.com/Profile/en-US/?user=Brownie%20PointsExecuting Commands from *any* event<p>Almost 3 years later we have a solution. The new blend behaviors api allows for custom trigger actions. I <a href="http://mbrownchicago.spaces.live.com/blog/cns!2221DC39E0C749A4!1324.entry">blogged about my ExecuteCommandAction here</a>.</p><hr class="sig">Keep your head in the Clouds as you're coding .NET http://azurecoding.netMon, 06 Apr 2009 21:45:13 Z2009-04-06T21:45:13Z