Cancel the Property Change

Topics: Issues / bugs
Jul 5, 2012 at 9:26 AM
Edited Jul 5, 2012 at 9:44 AM

Hello again

How is it possible to cancel that a property is changed.

Example:

Combobox with some values. The SelectedValue is bind to ActiveItem Property of ViewModel.

When I chosse an value in the combobox i want to  ask a Question with the IMessageService : Change the ActiveItem?
On CancelButton the ActiveItem and so the SelectedValue should not be changed.

Can I do this in PropertyChangedEvent?

Jul 6, 2012 at 8:51 AM

Maybe I found a Solution. But with a problem.

I add an Event to the CollectionViewSource of the Combobox:

CollectionViewSource.GetDefaultView(Recipes).CurrentChanging += RecipeViewCurrentChanging;

In theRecipeViewCurrentChanging i wan't to cancel the event. The problem is that the Event of the ActiveItem Property comes before the RecipeViewCurrentChanging event. :-(

How can I cancel ActiveItem PropertyChanged Event ?

Coordinator
Jul 6, 2012 at 10:32 AM

No. Models and view models in Catel have a PropertyChanging, but there is no way to cancel a change because that *could* cause integrity issues with models. If you want to cancel something from the outside, that is wrong. Then you have to implement this behavior with a custom property on the VM. If the user wants to really change it, change it in the model as well.

Jul 6, 2012 at 11:10 AM

Not realy clear.

The property is not in model just in viewmodel. I just want to cancel that the value is changed in the combobox.

Coordinator
Jul 7, 2012 at 1:24 PM

For now, it is not possible to "undo" a change except by just setting it back. We might implement a cancel option in the future, but the issue is that SL and WP7 and WinRT do not support INotifyPropertyChanging. We have to add this ourselves (not a big deal), but MS makes it hard for us to make sure everything keeps working on all platforms.

Jul 9, 2012 at 6:12 AM
Edited Jul 9, 2012 at 6:12 AM

Is there any workaround to get this functionality? I need this.

Coordinator
Jul 9, 2012 at 5:46 PM

The only 2 options you have at the moment are:

1) Set the previous value back yourself

2) Override SetValue and prevent it there, but you should be really careful with this.

Jul 10, 2012 at 6:06 AM
Edited Jul 10, 2012 at 6:07 AM

1). Thats not possible. When the value have changed a lot of other ViewModels are interested in this property. So i have do a lot of undo work.

2.) Thats wat I've done. Not so easy. Also work in CollectionViewSource.CurrentChanging to reset the value in the combobox.

Coordinator
Jul 11, 2012 at 8:47 AM

I agree that 2 isn't very easy, but I hope it does the job for you now. We will consider a cancel option in the OnPropertyChanging in the future.

Jul 12, 2012 at 7:18 AM

Thanks. Is there a Issue so where I can see when the feature is implemented.

Coordinator
Jul 12, 2012 at 7:22 AM

Yes.

http://catel.codeplex.com/workitem/7165

Jul 12, 2012 at 9:30 AM

Perfect.