We use a RadContextMenu where the user can right click to do actions like ViewModels methods like:
((CompanyGroupItemViewModel)treeViewListItem.ViewModel).EditItem();
it takes you to:
public void EditItem()
{
//Model.BeginEdit();
Bxf.Shell.Instance.ShowView("StaffSense.Views.OrgStructure.CompanyGroupEdit, StaffSense",
"companyGroupViewModelViewSource",
new CompanyGroupViewModel(Model),
"MainContent");
//Model.CancelEdit();
}
this take you to a new screen to change data of companyGroup... this works fine, but if you do it 3 times or next time the parent or child companygroup then it throws this error:
Edit level mismatch in CopyState
why?
like you see in the code I tried BeginEdit and CancelEdit, but it do nothing for I do not know any case how to implement the XXXEdit's because like i understand there is no need to, is this a bug in viewmodel model?
More details on when we get this error.
We use the example from the MVVM video series as basis. Our structure is a bit more complex with grand children.
our structure:
ER (OrgStructure)
EC (Company)
ECL (CompanyGroup List)
ER (Company Group)
bind to/from:
ViewModel (OrgStructureViewModel) //Model is ER (OrgStructure)
Dependency Object (CompanyItemViewModel): In order to bind to EditItem method
ViewModel (CompanyViewModel) //Model is EC (Company): In order to bind to Model. The model is passed from the CompanyItemViewModel
Dependency Objects (CompanyGroupItemViewModels)
Viewmodels (CompanyGroupViewModel) // Model is ER (Company Group)
We also build an observable collection from this structure for the tree where a property of the treeitem is the specific ItemViewModel
You can goto company group and edit the company group. As soon as you goto company to edit the company it throws an 'Edit level mismatch in CopyState' as soon as the model is assigned:
public CompanyGroupViewModel(CompanyGroupEC CompanyGroup)
{
Model = CompanyGroup; // throws error here
}
Not sure why it gives this error.
you press button test and then test 2 then throw error on test 2:
public void Test()
{
Presenter.ShowStatus(new Status { IsBusy = true, Text = "Change child..." });
CompanyGroupViewModel companyGroupViewModel = new CompanyGroupViewModel(((CompanyGroupItemViewModel)_treeViewList[0].Children[0].ViewModel).Model);
companyGroupViewModel.Model.Name = "Test";
OnPropertyChanged("OrgStructList");
Presenter.ShowStatus(new Status());
}
public void Test2()
{
Presenter.ShowStatus(new Status { IsBusy = true, Text = "change parent..." });
CompanyViewModel companyViewModel = new CompanyViewModel(((CompanyItemViewModel)_treeViewList[0].ViewModel).Model); // throw error here
companyViewModel.Model.CompanyName = "Test";
OnPropertyChanged("OrgStructList");
Presenter.ShowStatus(new Status());
}
this fix the error:
public CompanyGroupViewModel(CompanyGroupEC CompanyGroup)
{
ManageObjectLifetime = false; // must be false for all child objects, only want this in parent
Model = CompanyGroup;
}
Copyright (c) Marimer LLC