I am relatively new to WPF, so this may be trivial, but I couldn't figure this out.
Let's say I have a ListBox
and a Button
. The button is binded to a command that does something on the selected item of the list.
Example:
<ListBox Name="List" ItemsSource="{Binding Items}" />
<Button Content="Show!" Command="{Binding ShowCommand}" CommandParameter="{Binding ElementName=List, Path=SelectedItem}"/>
I want the button to be disabled if and only if no item is selected, and I ideally want to do it via the ShowCommand.CanExecute
function.
I tried checking for null parameter and it worked but if only checked once in the beginning. If I select an item the button is still disable.
I tried the suggestion here: WPF CommandParameter binding not updating but it simply didn't work... (same problem) Am I doing something wrong?
How do I make him recall canExecute
when I select an item on the list? .