Created
May 18, 2018 01:07
-
-
Save Majirefy/bdb8a98c3e84ccf80b704684eb6f0b42 to your computer and use it in GitHub Desktop.
OnAutoWireViewModelChanged event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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