I'm currently using CSLA 4.5 and am running into an issue where I get an error
Edit level mismatch in CopyState
What's strange is that if I execute a BeginEdit()
call on the business object in one section of code, it has no problem, but if I place it inside of my popup window logic, it throws this exception, and I'm not sure why. The key part that is weird is that it is the SAME OBJECT:
MainControl.xaml.cs
:
public void ShowPopup()
{
// ...
var target = ...;
//target.BeginEdit(); <== No problem if I uncomment this
var window = new PopupWindow
{
DataContext = new ConfirmationViewModel(target),
IsApplyCancel = true,
Owner = this,
};
window.Show();
}
PopuWindow.xaml.cs
:
public class PopupWindow : Window
{
private static void OnIsApplyCancelChanged(object sender, DependencyPropertyChangedEventArgs args)
{
var window = sender as Window;
if (window != null)
{
var context = window.DataContext as CSLAViewModelBase;
if (context != null)
{
var target = context.Target;
target.BeginEdit(); // EXCEPTION!!!
}
}
}
}
ConfirmationViewModel.cs
:
public class ConfirmationViewModel : CSLAViewModelBase
{
public ConfirmationViewModel(BusinessBase target)
: base(target) { ... }
}