Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Enabling commands with SelectedItems

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-15-2007   #1 (permalink)
Keith
Guest


 

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
Guest


 

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
Guest


 

Re: Enabling commands with SelectedItems

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

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
UAC re-enabling itself? void.no.spam.com Vista General 3 05-27-2008 03:18 PM
UAC re-enabling itself? void.no.spam.com Vista security 3 05-27-2008 03:18 PM
Enabling Fonts. louie Vista performance & maintenance 0 11-14-2007 11:28 PM
enabling PAE on RC2 Tim Draper Vista General 3 11-18-2006 05:05 AM
enabling right click =?Utf-8?B?ZmphY2s=?= Vista General 0 09-17-2006 07:37 AM


Update your Vista Drivers Update Your Vista Drivers Now!!

Vistax64.com 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 2005-2008
Page generated in 0.25494 seconds with 10 queries