How to tell which dataform button ended edit when using EventToCommand

Posted by Rodd on Stack Overflow See other posts from Stack Overflow or by Rodd
Published on 2010-05-03T18:38:00Z Indexed on 2010/05/03 23:28 UTC
Read the original article Hit count: 296

Filed under:
|

I'm new to SilverLight and Mvvm-Light. I have a DataForm on my view that displays/edits a SelectedPerson property (a Person object) of my view model.

I want to execute a command on my viewmodel when the user clicks the Save button but don't want to take action if the user clicks cancel.

I added the following to my ViewModel:

public RelayCommand PersonEditEnded {get; set;}
...
public void Initialize()
{
  PersonEditEnded = new RelayCommand(DoSomething);
  ...
}

public void DoSomething()
{
}

I added the following to my View:

<toolkit:DataForm x:Name="PersonForm" ... CurrentItem="{Binding SelectedPerson, Mode=TwoWay}">
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="EditEnded">
      <gs:EventToCommand Command="{Binding PersonEditEnded, Mode=OneWay}"/>
    </i:EventTrigger>
  </i:Interaction.Triggers>
</toolkit:DataForm>

This works and the DoSomething method is being called when the user presses Submit. However, DoSomething is also called when user presses Cancel. Is there a way to know which button was pressed or to supress the call when Cancel is pressed?

Thanks for whatever help you can offer!

© Stack Overflow or respective owner

Related posts about mvvm-light

Related posts about Silverlight