Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>According to the first question I posted, using CommandBindings in listbox it doesn't work. The implementation of CanExecute was:</p> <pre><code> private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = !cBgWorkers.isRunning; } </code></pre> <p>By doing WPF doesn't enable/disabled the listbox control automatically depending on the background worker state (Running or not) and I don't understand why because I have other controls like buttons with commands binded and WPF automatically enable/disable them.</p> <p>So I have done the following modification:</p> <pre><code> private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = !cBgWorkers.isRunning; if (LayoutListBox != null) LayoutListBox.IsEnabled = !cBgWorkers.isRunning; } </code></pre> <p>Now, it works. Listbox is enable when no background worker is running and disabled otherwise bu what I don't like is the last line placed into the method in where I enable/disable manually the property isEnabled of the listbox. It is inefficient so I would like to change isEnabled property of the listbox only when CanExecute changes its value. As far as I know there is a event to do this, it is CanExecuteChanged but I don't know how to implement it. Any ideas?</p> <p>Now, after trying several solutions, I am implementing the Mike's solution because I think it is easier and clearer and it can be re-used for other controls with only a few changes.</p>
 

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