This project has moved. For the latest updates, please go here.

Pass value by CommandParameter

May 18, 2010 at 4:12 AM

Plz help me, how about pass value by CommandParameter property.

May 18, 2010 at 9:09 AM

I don't know how to do this because I have never found the need to. I would consider passing the value seperately using a binding. If you go down the CommandParameter route you are in danger of introducing logic into the view which should be in the view model.

Coordinator
May 20, 2010 at 7:55 PM

The DelegateCommand implementation supports the CommandParameter property:

View:

<Button Command="{Binding SaveCommand}"  
        CommandParameter="{Binding SelectedItem,Element=listBox1}" />

ViewModel:

saveCommand = new DelegateCommand(Save);
...
private void Save(object parameter)
{
    Person selectedPerson = parameter as Person;    
... }
May 24, 2010 at 1:51 AM

Thanks Alot...

That works fine.