<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : DelegateCommand CanExecute and Async</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : DelegateCommand CanExecute and Async</description>
  <pubDate>Wed, 10 Jun 2026 05:33:32 -700</pubDate>
  <lastBuildDate>Fri, 14 Jun 2013 14:39:15 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=4178</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>DelegateCommand CanExecute and Async : Ok, I understand. I was executing...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16441#16441</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=118" rel="nofollow">LowOrbit</a><br /><strong>Subject:</strong> 4178<br /><strong>Posted:</strong> 14-Jun-2013 at 2:39pm<br /><br />Ok, I understand. I was executing the CanXX on a ContextMenu in this case. Since this method usually only gets executed when the menu is about to be displayed, I was hoping to save a trip to the database. <DIV>&nbsp;</DIV><DIV>Thanks!</DIV>]]>
   </description>
   <pubDate>Fri, 14 Jun 2013 14:39:15 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16441#16441</guid>
  </item> 
  <item>
   <title>DelegateCommand CanExecute and Async : CanXXX gets bound to the Enabled...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16440#16440</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 4178<br /><strong>Posted:</strong> 14-Jun-2013 at 2:29pm<br /><br />CanXXX gets bound to the Enabled property on the corresponding XAML control. That can't be asynchronous. I think you've got something upside down here. There should not be a need to query in a CanXXX method at all. You should do this query in Initialize and/or in response to an action that might change the result of that query. Store the boolean result in a private field that is returned by CanXXX. After running the query you call NotifyOfPropertyChange(x =&gt; CanXXX) to have the view reevaluate the binding.&nbsp;]]>
   </description>
   <pubDate>Fri, 14 Jun 2013 14:29:16 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16440#16440</guid>
  </item> 
  <item>
   <title>DelegateCommand CanExecute and Async : I started down the DelegateCommand...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16439#16439</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=118" rel="nofollow">LowOrbit</a><br /><strong>Subject:</strong> 4178<br /><strong>Posted:</strong> 14-Jun-2013 at 2:20pm<br /><br />I started down the DelegateCommand route and have since changed to the Caliburn.Micro way.<DIV>&nbsp;</DIV><DIV>But I still have the same problem. In the CanXX methods, I need to fetch data from the database via the UnitOfWork and return a boolean. The return value of these CanXX methods is a bool. I have to await the fetch from the database in order to return the proper value which means putting async on the method.</DIV><DIV>&nbsp;</DIV><DIV>You are not allowed to have a method defined as&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; async bool. You have to change it to "async Task" or "async Task&lt;xx&gt;". The DeletegateCommand CanExecute cannot point to this kind of method (hence the original question). Will the Caliburn.Micro CanXX version of a method defined as "async Task&lt;bool&gt;" work properly? </DIV><DIV>&nbsp;</DIV><DIV>Thanks </DIV><DIV>Robert</DIV>]]>
   </description>
   <pubDate>Fri, 14 Jun 2013 14:20:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16439#16439</guid>
  </item> 
  <item>
   <title>DelegateCommand CanExecute and Async : That&amp;#039;s what INotifyPropertyChanged...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16438#16438</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 4178<br /><strong>Posted:</strong> 14-Jun-2013 at 1:34pm<br /><br />That's what INotifyPropertyChanged is all about. You let the view know to refresh the binding once you you performed your async work.<div><br></div><div>Button states typically get initialized during VM initialization and may change in response to a user action. Both can be asynchronous. Enabling/Disabling should trigger a NotifyPropertyChanged in the Command so that the view refreshes the binding.&nbsp;</div><div><br></div><div>You simply perform your asynchronous query in response to a user action or during VM initialization and once the result comes back you enable/disable the command. You would typically disable all commands in the ctor, so that the user can't click anything until the view model is properly initialized and the appropriate buttons light up.&nbsp;</div><div><br></div><div>BTW, why are you using the DelegateCommand instead of Caliburn.Micro actions?&nbsp;</div><div><br></div><div>The following VM is somewhat of a good representation of what I'm talking about. Notice how UpdateCommands() is called in the appropriate places after something happens in the application and then UpdateCommands fires NotifyProperty changes on the various CanXXX properties to refresh the binding and have the appropriate buttons light up.&nbsp;</div><div><br></div><div><a href="https://github.com/IdeaBlade/Cocktail/blob/master/Samples/TempHire/TempHire/ViewModels/StaffingResource/ResourceMgtViewModel.cs" target="_blank">https://github.com/IdeaBlade/Cocktail/blob/master/Samples/TempHire/TempHire/ViewModels/StaffingResource/ResourceMgtViewModel.cs</a></div><div><br></div><div>The CanXXX doesn't need to be asynchronous. What matters is that you trigger a NotifyPropertyChanged when necessary, so the view triggers a reevaluation of the appropriate CanXXX properties.</div>]]>
   </description>
   <pubDate>Fri, 14 Jun 2013 13:34:44 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16438#16438</guid>
  </item> 
  <item>
   <title>DelegateCommand CanExecute and Async : In thinking about this more, this...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16437#16437</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=118" rel="nofollow">LowOrbit</a><br /><strong>Subject:</strong> 4178<br /><strong>Posted:</strong> 14-Jun-2013 at 9:39am<br /><br />In thinking about this more, this may be one of those cases where async is not appropriate. The DeletegateCommand's CanExecute is basically asking the question, "Can this method be executed?". If a method "could" be executed asyncronously, you have no idea on when the answer can be returned. This would have the effect of your button/menu/control being enabled/disabled at random times depending upon how long it takes for the async method to complete. <DIV>&nbsp;</DIV><DIV>The effect of this&nbsp;could be confusing, for example, if a menu item suddenly disables itself a few seconds after being displayed.</DIV><DIV>&nbsp;</DIV><DIV>So I guess I'm looking for a little guidance on how to handle this scenario? I am using Cocktail and the UnitOfWork stuff. All queries are executed asyncronously. How would I execute the query and get the answer back to the delegatecommand when forced to do queries asyncronously?</DIV><DIV>&nbsp;</DIV><DIV>Thanks!</DIV>]]>
   </description>
   <pubDate>Fri, 14 Jun 2013 09:39:56 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16437#16437</guid>
  </item> 
  <item>
   <title>DelegateCommand CanExecute and Async : Hello  I have a DeletegateCommand...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16436#16436</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=118" rel="nofollow">LowOrbit</a><br /><strong>Subject:</strong> 4178<br /><strong>Posted:</strong> 14-Jun-2013 at 9:06am<br /><br />Hello<DIV>&nbsp;</DIV><DIV>I have a DeletegateCommand object for a button I my UI. In the CanExecute method of the delegate, I need to execute a query against the database to see if a user is allowed to press the button based on the context of the data they are on. The normal signature of the CanExecute is a Func&lt;bool&gt;. </DIV><DIV>&nbsp;</DIV><DIV>I cannot figure out how to call an async method that returns a bool. In order to return a bool, the signature needs to be a Task&lt;bool&gt; but then it doesn't match the DelegateCommand signature for CanExecute. </DIV><DIV>&nbsp;</DIV><DIV>Can you provide some guidance or an example on how to specifiy a method for CanExecute than can execute a async method that returns a bool?</DIV><DIV>&nbsp;</DIV><DIV>Thanks!</DIV>]]>
   </description>
   <pubDate>Fri, 14 Jun 2013 09:06:20 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4178&amp;PID=16436#16436</guid>
  </item> 
 </channel>
</rss>