I'm preparing an MVVM presentation for the rest of my team, and as such have treated it as if I didn't know anything about it. I've sailed through the easy things, promoting a design where the only connection between Views and ViewModels is the contract given by the properties and commands. Towards the end, I wanted to pick one of our app's pages and showcase how it would be easier to manage and, more importantly, possible to test with MVVM. But I hit a snag.
The page has a control that serves as a status notification. When some condition is met, it fades in, and when a timeout occurs, it fades out. I'm trying to decide how to describe this in terms of MVVM, and I'm stuck. It doesn't seem like there's much discussion here or elsewhere that discusses a clean way to handle XF animations.
Without MVVM, it's straightforward. When the condition is met, a dependency raises an event. The Page handles the event and starts the fade-in animation, starting the timeout as a continuation at the end of the fade-in.
From an MVVM standpoint, I'm stumped.
- Without a fade animation, the ViewModel could have a bool IsVisible property bound to the notification's similar property. I could have a NotificationOpacity property on the ViewModel, but animation is a concept that requires a View and my VM would need an explicit reference. Bleh.
- I can't see a way a Command could dig me out, other than taking a View as a parameter and initiating the fade. This feels like pushing View details into the ViewModel layer.
- I could put a public method that starts the fade in/out on the Page, but this would mean the VM needs a reference to the View.
Since the page had to ship, it's doing something like the third method. The Page implements an INotificationDisplay interface, and the ViewModel receives the page via a constructor parameter typed to this reference.
I just noticed Triggers, and it seems like WPF had some functionality in XAML to describe animation storyboards kicked off by triggers. It seems like I could create a TriggerAction with my notification logic, set that up inside the View, but when I tried it I discovered the trigger's property has to be a BindableProperty. That suggests it isn't really meant to target ViewModel properties.
So what are people doing to trigger animations in an MVVM implementation?