Skip to content

Instantly share code, notes, and snippets.

@Majirefy
Created May 18, 2018 01:07
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 Majirefy/bdb8a98c3e84ccf80b704684eb6f0b42 to your computer and use it in GitHub Desktop.
Save Majirefy/bdb8a98c3e84ccf80b704684eb6f0b42 to your computer and use it in GitHub Desktop.
OnAutoWireViewModelChanged event
private static void OnAutoWireViewModelChanged(BindableObject bindable, object oldValue, object newValue)
{
    var view = bindable as Element;
    if (view == null)
    {
        return;
    }
    var viewType = view.GetType();
    var viewName = viewType.FullName.Replace(".Views.", ".ViewModels.");
    var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
    var viewModelName = string.Format(
        CultureInfo.InvariantCulture, "{0}Model, {1}", viewName, viewAssemblyName);
    var viewModelType = Type.GetType(viewModelName);
    if (viewModelType == null)
    {
        return;
    }
    var viewModel = _container.Resolve(viewModelType);
    view.BindingContext = viewModel;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment