Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling SaveViewModelAsync() twice #1226

Closed
RCP161 opened this issue Oct 19, 2018 · 10 comments
Closed

Calling SaveViewModelAsync() twice #1226

RCP161 opened this issue Oct 19, 2018 · 10 comments

Comments

@RCP161
Copy link

RCP161 commented Oct 19, 2018

If I use the CancelViewModelAsync() Method, the ViewModel doesn't get the PropertyChanged of the Model anymore. So if I edit the ViewModel again, the changes will be written to the Model, but changes on other Properties will not be shown in the ViewModel.
Addtional to that, if i call CancelViewModelAsync() the second time, nothing happend.

Steps to reproduce

Done in this TestRepo: https://github.com/RCP161/IDataObjectTest/tree/master/M1Vm2

  1. Start the program and change one value. Leave the field, so that the Property updates. The State TextBlock changes.
  2. Click Revert to call CancelViewModelAsync() and change the value again.

=> The TextBlock does not change the state anymore. You can trace the problem in the output window.

  1. Click Revert again.

=> Nothing happened.

Platform:
.NET version: 4.6.1

Expected behaviour

The ViewModel should still listen on the PropertyChanged of the Model.
The CancelViewModelAsync (or SaveViewModelAsync) should be called more times than one.

Actual behaviour

ViewModel dosen't listen to the PropertyChanged of the Model anymore.
Can't call ((System.ComponentModel.IEditableObject)this).BeginEdit(); to use the functionality again. So nothing happened.

@GeertvanHorrik
Copy link
Member

A model only has a single backup at a time. We don't have plans to support multiple backup scenarios at the same time.

@RCP161
Copy link
Author

RCP161 commented Oct 22, 2018

You don’t have to do this as default.
What I need to know is, how I can create a new backup, so that I can call it by myself. The problem is, that it doesn't work, like it is described in the comment of this answer and here in the actual behavior with the ((System.ComponentModel.IEditableObject)this).BeginEdit();.
Also, I need the behavior, that the ViewModel should listen to the Model, until it is not needed anymore. For Example, if the usercontrol will be unloaded or so.

Or what is the common scenario for this? Have I to change the view after calling cancel or save?

@stale
Copy link

stale bot commented Dec 21, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 21, 2018
@stale stale bot closed this as completed Dec 28, 2018
@RCP161
Copy link
Author

RCP161 commented Jan 8, 2019

Hi,
I don't need multiple backup scenarios at the same time. I need a new backup cycle, after calling CancelViewModelAsync or SaveViewModelAsync.

@GeertvanHorrik
Copy link
Member

What do you mean by: "a new backup cycle"? Maybe we can make some methods protected virtual so you can customize the model behavior?

@RCP161
Copy link
Author

RCP161 commented Jan 8, 2019

Like I explained,
I edit the data and save (or revert). After that, I would expect, that this back up mechanism will start again, so that I can use it multiple times. Like a cycle.

Edit data - Save - Back up will be replaced with new data;
Edit data again - Save - Back up will be replaced with new data;
Edit data again - Cancel - Data will be reverted withe back up;

All without closing the view, so that the view, the model and the viewmodel is all time the same. I dind't find this use case in the examples.

@RCP161
Copy link
Author

RCP161 commented Jan 10, 2019

Is this possible?

@GeertvanHorrik
Copy link
Member

We can't just reply instantly, we have other stuff to do as well (actually make some money to keep supporting this as well). As soon as we have time to answer this question, we will. For now, you can look at our options over at Open Collective: https://opencollective.com/catel

@GeertvanHorrik
Copy link
Member

At the moment, whenever a VM is saved, it will call EndEdit on the IEditableObject interface. It has no intention of re-initiating a backup because Catel assumes a VM will only be saved once (and disposed after that). In your case, you can call base.SaveAsync and then initialize a BeginEdit again with the new values if you want to keep the vm alive.

@lock
Copy link

lock bot commented Aug 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants