Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Enabling commands with SelectedItems

 
 
Old 06-15-2007   #1 (permalink)
Keith


 
 

Enabling commands with SelectedItems

I'm implementing an application in the DataModel-ViewModel-View
pattern and I'm having some trouble with commands bound to a listbox.
What I'd like to happen is for a given command to be enabled/disabled
based on the number of SelectedItems. Here's some of the relevant code
so far:

<StackPanel>
<Button
Command="{Binding Path=MyCommand}"
CommandParameter="{Binding Source=ListBox1,
Path=SelectedItems}"
>

Command
</Button>
<ListBox x:Name="ListBox1" ItemsSource="..."/>
</StackPanel>

In my code-behind I have a class derived from ICommand that implements
CanExecute() and Execute(). CanExecute() is called on creation of the
command and immediately before it is invoked by clicking the button,
but it is not called when SelectedItems changes.

I thought that CanExecute() would be called each time SelectedItems
changed and should enable/disable the button as appropriate. Am I
missing something?

Cheers,
Keith


My System SpecsSystem Spec
Old 06-16-2007   #2 (permalink)
Keith


 
 

Re: Enabling commands with SelectedItems

Answered my own question: CanExecuteChanged must be called by the
ICommand implementation.

My System SpecsSystem Spec
Old 06-16-2007   #3 (permalink)
Keith


 
 

Re: Enabling commands with SelectedItems

Answered my own question: CanExecuteChanged must be called by the
ICommand implementation.

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Enabling S.M.A.R.T Software
UAC re-enabling itself? Vista General
UAC re-enabling itself? Vista security
Enabling Fonts. Vista performance & maintenance
enabling PAE on RC2 Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46