Skip to content

Instantly share code, notes, and snippets.

@PulkitSethi1984
Created May 15, 2018 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PulkitSethi1984/8b9d30e0793fadb4677a7d0ad192c18e to your computer and use it in GitHub Desktop.
Save PulkitSethi1984/8b9d30e0793fadb4677a7d0ad192c18e to your computer and use it in GitHub Desktop.
using System;
using System.Reflection;
using System.Threading.Tasks;
using App.Common.Core.ViewModels;
using Xamarin.Forms;
namespace App.Common.Core.Services.App
{
public class NavigationService : INavigationService
{
public NavigationService()
{
}
public async Task NavigateToAsync<TViewModel>(object parameter)
{
var vmType = typeof(TViewModel);
var viewType = Type.GetType($"{vmType.FullName.Replace("Model", string.Empty)}, {vmType.GetTypeInfo().Assembly.FullName}");
Page page = Activator.CreateInstance(viewType) as Page;
if(page.BindingContext is BaseViewModel vm)
await vm.InitAsync(parameter);
await Application.Current.MainPage.Navigation.PushAsync(page, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment