Note that there are some explanatory texts on larger screens.

plurals
  1. PORefresh WPF Command
    primarykey
    data
    text
    <p>Does anyone know how I can force <code>CanExecute</code> to get called on a custom command (Josh Smith's <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="noreferrer"><code>RelayCommand</code></a>)?</p> <p>Typically, <code>CanExecute</code> is called whenever interaction occurs on the UI. If I click something, my commands are updated. </p> <p>I have a situation where the condition for <code>CanExecute</code> is getting turned on/off by a timer behind the scenes. Because this is not driven by user interaction, <code>CanExecute</code> is not called until the user interacts with the UI. The end result is that my <code>Button</code> remains enabled/disabled until the user clicks on it. After the click, it is updated correctly. Sometimes the <code>Button</code> appears enabled, but when the user clicks it changes to disabled instead of firing.</p> <p>How can I force an update in code when the timer changes the property that affects <code>CanExecute</code>? I tried firing <code>PropertyChanged</code> (<code>INotifyPropertyChanged</code>) on the property that affects <code>CanExecute</code>, but that did not help.</p> <p>Example XAML:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Button Content="Button" Command="{Binding Cmd}"/&gt; </code></pre> <p>Example code behind:</p> <pre class="lang-cs prettyprint-override"><code>private ICommand m_cmd; public ICommand Cmd { if (m_cmd == null) m_cmd = new RelayCommand( (param) =&gt; Process(), (param) =&gt; EnableButton); return m_cmd; } // Gets updated from a timer (not direct user interaction) public bool EnableButton { get; set; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload