I'm building a cross platform app in Xamarin using MvvmCross, I've declared my ViewModels in my core and am working on my Windows 8 project first, which thanks to Stuart Lodge who answered me previously with this link, I can bind a Page's Loaded event as such (using the Interactivity dll):
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding MyICommandThatShouldHandleLoaded}" />
</i:EventTrigger>
</i:Interaction.Triggers>
How can I do the same using MvvmCross in Android?
Thanks!
Can you tell what you are trying to accomplish on the loaded event?
When trying to implement a view-model, usually I don't want tothink in terms of the UI.
The UI can work differently depending on the platform.
One way to think when implementing a view-model is think that you will want to use the view-models for testing, with no UI. In this case, your app should be able to run with no UI attached. If you need user input (like Username and Password), the test code you write is setting the properties of the view model, similar to how the data-binding is doing it when the UI is bound to these properties:
loginViewModel.Username = "admin";
loginViewModel.Password = "12345";
For example, In the link you gave, I am not sure why would be needed to know about the mainwindow loaded event to show the login screen.
The MainViewModel coressponding to the main window could call
pulic class MainViewModel : MvxViewModel
{
public void Init()
{
ShowViewModel<LoginViewModel>();
}
}
This is just an example, it might not be so good, but I am just trying to show a different way.
Remember that from a view-model perspective, the ShowViewModel doesn't mean too much.
The view-model just calls to show another view-model, something which is 'somehow' connected to a view. It can mean showing a popup, or navigating to another page / window, etc. The view-model doesn't need to know. This is mainly because the UI can work differently on each platform, or the UI requirements can be different on each platform (because the UI patterns can be different) .
MvvmCross has a nice way to detour the default ShowViewModel behavior (by writing a platform specific custom presenter). Basically, you get in control of how a ShowViewModel request for a view-model type is executed on the platform.