views:

894

answers:

2

I've a data form in SL3 which uses Prisms Commands with Attached Behaviour for trapping events.

(It fairly tightly follows this blog post: http://blogs.southworks.net/dschenkelman/2009/04/18/commands-with-attached-behavior-for-silverlight-3-dataform/#comment-607)

Basically, it's all hooked up and working fine, however in the viewmodel, I can't see how I can access the event args for the event.

In the constructor of the VM I define the delegate command:

this.EditEnded = new DelegateCommand<object>(o => {
    //how can I tell if the button clicked was cancel or save?
}

But I need access to the DataFormItemEditEndedEventArgs property to so I can define what needs to be done? I want to perform different actions depending if the user cancelled or committed.

+1  A: 

To get the parameter back, you could edit your CommandBehaviorBase derived class like this:

private void ItemEditEnded(object sender, DataFormItemEditEndedEventArgs e)
{
     this.CommandParameter = e.EditAction;
     ExecuteCommand();
}

This would send the EditAction (or whatever else you want) to the CommandDelegate. In this case, you would not add an attached property for the parameter. Edit your attached property class appropriately (leave out the CommandParameter). I'm not in love with this approach (seems kinda non-standard), and I wonder if someone else has an alternate suggestion.

I mean, you could always add events for the different kinds of events (one for commit, etc.), and that's a little more pure, but it would mean a lot of extra code. You could get away with it in this instance, but for other events, it would become impossible (communicating mouse coordinates or something ridiculous).

My video on Prism Commands. deals with more static parameters See the "Command Parameters" section for how to sort out the methods based a static attached property.

<Button Content="Save"
        HorizontalAlignment="Center"
        VerticalAlignment="Bottom"
        cal:Click.Command="{Binding GetCompanyData}"
        cal:Click.CommandParameter="SaveButton"
        />
Erik Mork
Hi Erik, I've already seen your screencast, it was an enomous help in me getting this far. I still don't see how this can be used to get the event args however? Could you elaborate?
DaRKoN_
I answered too quickly. I've provided an alternate suggestion above.
Erik Mork
A: 

Maybe you should declare seperate Commands (SaveCommand and CancelCommand) for seperate buttons and actions.

Andrej