I have a Silverlight 4 application and just recently added some validation to one of my root object's children. One of their fields value must be greater than 1, so I added a new business rule:
The children are displayed in a datagrid and the save, cancel and delete are linked to the root.
If I change the value of other fields of the children and click Cancel, the data is refreshed, no problem. If I change this particular property's value to 0 to generate a broken rule, the cancel button remains enabled (fine) but I get the an error saying "Edit level mismatch in UndoChanges " when I click on it. I am not setting "ManageObjectLifetime=false;" in my viewmodel because it worked without it and if I do, then the UI will not refresh at all.
Is this a bug, or am I missing something?
What is the MyProperty datatype?
Must be something you are missing because a validation rule will not change EditLevel.
Its an integer (int).
I compared other viewmodels-views in the same application and noticed that the Cancel button is disabled if a broken rule is found. In the case above, the Cancel button is still enabled (which I thougth was fine but maybe its not). the problem mentionned in my previous post may actually not be the issue. I'll you know if I find anything. Thanks.
No still the same issue. Turns out the Cancel button is only disabled if the error is a variable type error (ex. leaving a blank in an integer text field). I tested my library and I do get the desired behaviour. The edit level for the root and children are the same. It seems I only (in this case) get this problem using Silverlight's datagrid when editing children. If a required field rule is borken at the root level, cliking Cancel works as expected.
Not sure if this is the most elegant way to solve this problem but I'll share it anyway.
After reading this from a previous blog (http://forums.lhotka.net/forums/p/11073/51471.aspx#51471)
"In a detail form bound to a single object, that object clearly has currency. In a datagrid or other complex binding control that is bound to a list, only one object in the list will have currency. As the user moves from row to row currency is automatically moved/managed by the WinForms binding source object. With parent-child objects, the most common scenario is that the parent object is bound to a form, so it has currency. Then the child collection is bound to a datagrid or something like that. So one child has currency too (because this is a separate binding source). Before you can save, you must first unbind the child collection properly. And that usually means manually calling EndEdit on the current row, because data binding won't do that automatically ",
I decide to add the follwing code in the codebehind of my view:
private void CancelButton_Click(object sender, RoutedEventArgs e)
I believe this change is acceptable since its really a issue specific to the UI and not the library.
Copyright (c) Marimer LLC