Skip to content

Instantly share code, notes, and snippets.

@codemillmatt
Last active April 16, 2016 00:27
Show Gist options
  • Save codemillmatt/0b5a360e3330289fb90a6b6eba381c8c to your computer and use it in GitHub Desktop.
Save codemillmatt/0b5a360e3330289fb90a6b6eba381c8c to your computer and use it in GitHub Desktop.
Xamarin Forms VM First Nav - Passing Parameters
public async Task PushAsync<T>(Action<T> initialize = null) where T : BaseViewModel
{
T viewModel;
// First instantiate the view model
// "IoC" is a static AutoFac IContainer property in the main Xam Forms Application class
using (var scope = App.IoC.BeginLifetimeScope ()) {
viewModel = App.IoC.Resolve<T> ();
if (initialize != null)
{
initialize.Invoke(viewModel);
}
}
var view = InstantiateView (viewModel);
await FormsNavigation.PushAsync ((Page)view);
}
// Invoke the service like this
await _navService.PushAsync<DetailViewModel>(vm =>
vm.InitializeDisplay("Interesting Stuff", anotherVariable, "more stuff")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment