So I'm having this problem that hopefully you can help with.
I'm writing a WPF application using MVVM Light as a framework. In this situation, I have a list of items, and the SelectedItem is bound to a details view where the user can edit the item. There is a Save button in this case for explicit saving of data.
My problem is that when the user edits the data, the changes immediately shows up in the list. If the user cancels, it resets the selected item, but it's still changed. How do I prevent changes from propogating?
I tried to implement a cloning implementation, but as soon as I did that, MVVM Light's messaging system ends up getting into a loop, resulting in a StackOverflowException due to the fact that I keep cloning the object. As well, the clone implementation is ugly.
Any idea on how I can do this properly?
EDIT:
Basic XAML for list view:
<DataGrid DataContext="{Binding SubJobTypes}"
ItemsSource="{Binding}"
SelectedItem="{Binding ElementName=Root, Path=DataContext.SelectedSubJobType, Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}"/>
</DataGrid.Columns>
</DataGrid>
Basic XAML for edit view:
<StackPanel>
<StackPanel>
<StackPanel Orientation="Horizontal" DataContext="{Binding Path=CurrentSubJobType}">
<TextBlock Text="Name"/>
<TextBox Text="{Binding Path=Name, Mode=TwoWay}" Width="150"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="{Binding Path=SubmitCommandText, FallbackValue=Submit}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding Path=SaveSubJobTypeCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button Content="Cancel" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding Path=CancelCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button Content="Delete">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding Path=DeleteCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
</StackPanel>
</StackPanel>
ViewModels are standard, won't bother posting