I am developing my first app using Xamarin.Forms and FreshMVVM as the architecture and I am still having some trouble when understanding MVVM, more specifically, where animations should be handled, in the View or in the ViewModel?. I understand that for events that require using the Model, transitions between Views and other stuff that are not strictly related to the UI are handled in the ViewModel with bindings and commands. But does the ViewModel handle all events? What if the events only modify the appearance of the UI?. For example, changing a button's BackgroundColor when pressing it, in this scenario, the backgroundColor should be changed in the Clicked() event in the view's code-behind or in the command of the ViewModel? Or if I wanna make an animation when the View is disappearing should I implement it in the OnDisappearing() event in the view's code-behind, or in the ViewModel?
I have tried to find an answer but I have not been able to extrapolate their MVVM explanations to this specific scenario, so I would appreciate an explanation. That is all, thank you all for your time.
Much of the MVVM pattern is open to interpretation.
In most projects there comes a point where the time taken to enforce a strict demarcation of work between ViewModel and View behaviour can be detrimental to time scales.
Personally, I ensure that all of the business logic is kept strictly within the ViewModel and Model the aim being that the system should still work even if the UI was replaced by code.
I try and keep as much UI stuff, including animations in the View and that may mean putting quite a bit of code into the code behind to support it. Don't forget that this may also includes code libraries that are only utilized by the XAML such as value convertors, say to use a Boolean property in the ViewModel to switch the background colour of a view.
Sometimes though you may need to have the ViewModel manipulate some data only so that the View can present it.
This I would deem, pragmatically, acceptable BUT the ViewModel should NEVER reference UI controls directly, only present data.
In the case of triggering animations or events in the UI I personally don't have an issue with having a ViewModel property that is used for this purpose although some may argue otherwise.
In the examples that you mention I think that can all be performed in the code behind or using convertors in the xaml.